-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Zorkaltsev
committed
Jan 27, 2024
1 parent
45a065c
commit 19c26f9
Showing
20 changed files
with
1,071 additions
and
1,049 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './query-client'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.