File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ process . env . YDB_SDK_PRETTY_LOGS = '1' ;
2+
3+ import { Driver , getCredentialsFromEnv , Logger } from 'ydb-sdk' ;
4+ import { main } from '../utils' ;
5+
6+ async function run ( logger : Logger , endpoint : string , database : string ) {
7+ const authService = getCredentialsFromEnv ( ) ;
8+ logger . info ( 'Driver initializing...' ) ;
9+ const driver = new Driver ( { endpoint, database, authService } ) ;
10+ const timeout = 10000 ;
11+ if ( ! await driver . ready ( timeout ) ) {
12+ logger . fatal ( `Driver has not become ready in ${ timeout } ms!` ) ;
13+ process . exit ( 1 ) ;
14+ }
15+
16+ await driver . queryClient . do ( {
17+ fn : async ( session ) => {
18+ const res = await session . execute ( { text : `SELECT 1;` , } ) ;
19+
20+ // Always drain the result to avoid session stuck
21+ for await ( const resultSet of res . resultSets ) {
22+ for await ( const row of resultSet . rows ) {
23+ }
24+ }
25+ } ,
26+ onTrailer : ( trailer ) => {
27+ let consumedUnits = trailer . get ( 'x-ydb-consumed-units' )
28+ if ( consumedUnits ) {
29+ console . info ( `Consumed units: ${ consumedUnits } ` ) ;
30+ }
31+ }
32+ } ) ;
33+
34+ await driver . destroy ( ) ;
35+ }
36+
37+ main ( run ) ;
You can’t perform that action at this time.
0 commit comments