Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Zorkaltsev committed Jan 27, 2024
1 parent 45a065c commit 19c26f9
Show file tree
Hide file tree
Showing 20 changed files with 1,071 additions and 1,049 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
with:
github-token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
npm-token: ${{ secrets.NODE_AUTH_TOKEN }}
npm-dist-tag: beta
npm-dist-tag: rc
93 changes: 7 additions & 86 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"luxon": "^3.2.1",
"reflect-metadata": "^0.1.13",
"uuid": "^8.3.2",
"ydb-sdk-proto": "^1.1.0"
"ydb-sdk-proto": "^1.2.1"
},
"devDependencies": {
"@commitlint/cli": "^17.6.1",
Expand Down
1 change: 1 addition & 0 deletions query/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './query-client';
68 changes: 68 additions & 0 deletions query/query-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {Ydb} from "ydb-sdk-proto";
import QueryService = Ydb.Query.V1.QueryService;
import CreateSessionRequest = Ydb.Query.CreateSessionRequest;
import CreateSessionResult = Ydb.Query.CreateSessionResult;
import EventEmitter from "events";
import {IClientSettings, SessionPool} from "./session-pool";
import {Endpoint} from "../discovery";
import {IAuthService} from "../credentials";
import {Logger} from "../logging";
import {ISslCredentials} from "../ssl-credentials";
import {AuthenticatedService, ClientOptions, getOperationPayload, pessimizable} from "../utils";
import {SessionCreator} from "../table";
import {retryable} from "../retries";
import {QuerySession} from "./query-session";

export class QuerySessionCreator extends AuthenticatedService<QueryService> {
public endpoint: Endpoint;
private readonly logger: Logger;

constructor(endpoint: Endpoint, database: string, authService: IAuthService, logger: Logger, sslCredentials?: ISslCredentials, clientOptions?: ClientOptions) {
const host = endpoint.toString();
super(host, database, 'Ydb.Query.V1.QueryService', QueryService, authService, sslCredentials, clientOptions);
this.endpoint = endpoint;
this.logger = logger;
}

@retryable()
@pessimizable
async create(): Promise<QuerySession> {
const response = await this.api.createSession(CreateSessionRequest.create());
const payload = getOperationPayload(response);
const {sessionId} = CreateSessionResult.decode(payload);
return new QuerySession(this.api, this.endpoint, sessionId, this.logger, this.getResponseMetadata.bind(this));
}
}

class QuerySessionPool extends SessionPool<QuerySession> {
protected getSessionServiceCreator(
endpoint: Endpoint,
database: string,
authService: IAuthService,
logger: Logger,
sslCredentials: ISslCredentials | undefined,
clientOptions: ClientOptions | undefined): SessionCreator<QuerySession> {
return new QuerySessionCreator(endpoint, database, authService, logger, sslCredentials, clientOptions);
}
}

export class QueryClient extends EventEmitter {
private pool: QuerySessionPool;

constructor(settings: IClientSettings) {
super();
this.pool = new QuerySessionPool(settings);
}

public async withSession<T>(callback: (session: QuerySession) => Promise<T>, timeout: number = 0): Promise<T> {
return this.pool.withSession(callback, timeout);
}

public async withSessionRetry<T>(callback: (session: QuerySession) => Promise<T>, timeout: number = 0, maxRetries = 10): Promise<T> {
return this.pool.withSessionRetry(callback, timeout, maxRetries);
}

public async destroy() {
await this.pool.destroy();
}
}
21 changes: 21 additions & 0 deletions query/query-session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Session} from "../table";
import {Endpoint} from "../discovery";
import {Logger} from "../logging";
import * as grpc from "@grpc/grpc-js";
import {Ydb} from "ydb-sdk-proto";
import QueryService = Ydb.Query.V1.QueryService;

export class QuerySession extends Session<any> {

constructor(
api: QueryService,
endpoint: Endpoint,
sessionId: string,
logger: Logger,
getResponseMetadata: (request: object) => grpc.Metadata | undefined
) {
super(api, endpoint, sessionId, logger, getResponseMetadata);
}

// TODO: Add methods
}
2 changes: 1 addition & 1 deletion src/__tests__/alter-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Column,
TableDescription,
TableIndex,
} from '../table/table-client';
} from '../table/table-session';
import { Types } from '../types';
import {OperationParams} from "../table/session";

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/bulk-upsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Row,
TABLE
} from '../test-utils';
import {TableSession} from '../table/table-client';
import {TableSession} from '../table/table-session';
import {Ydb} from 'ydb-sdk-proto';

async function readTable(session: TableSession): Promise<Row[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/bytestring-identity.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Driver from '../driver';
import {destroyDriver, initDriver, TABLE} from '../test-utils';
import {Column, TableSession, TableDescription} from '../table/table-client';
import {Column, TableSession, TableDescription} from '../table/table-session';
import {declareType, TypedData, Types} from '../types';
import {withRetries} from '../retries';

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/create-table.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Driver from '../driver';
import {destroyDriver, initDriver} from '../test-utils';
import {Column, DescribeTableSettings, TableDescription} from '../table/table-client';
import {Column, DescribeTableSettings, TableDescription} from '../table/table-session';
import {TypedValues, Types} from '../types';
import Long from 'long';
import {Ydb} from 'ydb-sdk-proto';
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/read-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Row,
TABLE
} from '../test-utils';
import {ReadTableSettings, TableSession} from '../table/table-client';
import {ReadTableSettings, TableSession} from '../table/table-session';
import {TypedValues, TypedData} from '../types';

async function readTable(session: TableSession, settings: ReadTableSettings): Promise<TypedData[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/scan-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
initDriver,
Row,
} from '../test-utils';
import {TableSession} from '../table/table-client';
import {TableSession} from '../table/table-session';
import {TypedData} from '../types';

async function executeScanQuery(session: TableSession): Promise<TypedData[]> {
Expand Down
18 changes: 14 additions & 4 deletions src/driver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import DiscoveryService from './discovery';
import {TableClient} from './table/table-client';
import SchemeService from './scheme';
import {SchemeClient} from './scheme';
// import {QueryClient} from './query/query-client';
import {ENDPOINT_DISCOVERY_PERIOD} from './constants';
import {IAuthService} from './credentials';
import {TimeoutExpired} from './errors';
import {getLogger, Logger} from './logging';
import SchemeClient from './scheme';
import {ClientOptions} from './utils';
import {parseConnectionString} from './parse-connection-string';
import {makeSslCredentials, ISslCredentials} from './ssl-credentials';
import {TableClient} from "./table/table-client";

export interface IPoolSettings {
minLimit?: number;
Expand Down Expand Up @@ -38,7 +38,8 @@ export default class Driver {
private discoveryService: DiscoveryService;

public tableClient: TableClient;
public schemeClient: SchemeService;
public schemeClient: SchemeClient;
// public queryClient: QueryClient;

constructor(settings: IDriverSettings) {
this.logger = settings.logger || getLogger();
Expand Down Expand Up @@ -79,6 +80,15 @@ export default class Driver {
discoveryService: this.discoveryService,
logger: this.logger,
});
// this.queryClient = new QueryClient({
// database: this.database,
// authService: this.authService,
// sslCredentials: this.sslCredentials,
// poolSettings: this.poolSettings,
// clientOptions: this.clientOptions,
// discoveryService: this.discoveryService,
// logger: this.logger,
// });
this.schemeClient = new SchemeClient({
database: this.database,
authService: this.authService,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export {
ExecutionPolicy,
CachingPolicy,

} from './table/table-client';
} from './table/table-session';
export {
MakeDirectorySettings,
RemoveDirectorySettings,
Expand Down
2 changes: 1 addition & 1 deletion src/scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface ISchemeClientSettings {
logger: Logger;
}

export default class SchemeClient extends EventEmitter {
export class SchemeClient extends EventEmitter {
private schemeServices: Map<Endpoint, SchemeService>;

constructor(private settings: ISchemeClientSettings) {
Expand Down
1 change: 1 addition & 0 deletions src/table/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './session-pool';
export * from './session';
export * from './table-client';
export * from './table-session';
Loading

0 comments on commit 19c26f9

Please sign in to comment.