@@ -46,15 +46,15 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
4646
4747 private connection : IThriftConnection | null ;
4848
49- private statusFactory : StatusFactory ;
49+ private readonly statusFactory : StatusFactory ;
5050
5151 private connectionProvider : IConnectionProvider ;
5252
5353 private authProvider : IAuthentication ;
5454
55- private logger : IDBSQLLogger ;
55+ private readonly logger : IDBSQLLogger ;
5656
57- private thrift = thrift ;
57+ private readonly thrift = thrift ;
5858
5959 constructor ( options ?: ClientOptions ) {
6060 super ( ) ;
@@ -89,7 +89,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
8989 * @example
9090 * const session = client.connect({host, path, token});
9191 */
92- async connect ( options : ConnectionOptions , authProvider ?: IAuthentication ) : Promise < IDBSQLClient > {
92+ public async connect ( options : ConnectionOptions , authProvider ?: IAuthentication ) : Promise < IDBSQLClient > {
9393 this . authProvider =
9494 authProvider ||
9595 new PlainHttpAuthentication ( {
@@ -143,43 +143,39 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
143143 * @example
144144 * const session = await client.openSession();
145145 */
146- openSession ( request : OpenSessionRequest = { } ) : Promise < IDBSQLSession > {
146+ public async openSession ( request : OpenSessionRequest = { } ) : Promise < IDBSQLSession > {
147147 if ( ! this . connection ?. isConnected ( ) ) {
148- return Promise . reject ( new HiveDriverError ( 'DBSQLClient: connection is lost' ) ) ;
148+ throw new HiveDriverError ( 'DBSQLClient: connection is lost' ) ;
149149 }
150150
151151 const driver = new HiveDriver ( this . getClient ( ) ) ;
152152
153- return driver
154- . openSession ( {
155- client_protocol_i64 : new Int64 ( TProtocolVersion . SPARK_CLI_SERVICE_PROTOCOL_V6 ) ,
156- ...getInitialNamespaceOptions ( request . initialCatalog , request . initialSchema ) ,
157- } )
158- . then ( ( response ) => {
159- this . statusFactory . create ( response . status ) ;
160- return new DBSQLSession ( driver , definedOrError ( response . sessionHandle ) , this . logger ) ;
161- } ) ;
153+ const response = await driver . openSession ( {
154+ client_protocol_i64 : new Int64 ( TProtocolVersion . SPARK_CLI_SERVICE_PROTOCOL_V6 ) ,
155+ ...getInitialNamespaceOptions ( request . initialCatalog , request . initialSchema ) ,
156+ } ) ;
157+
158+ this . statusFactory . create ( response . status ) ;
159+ return new DBSQLSession ( driver , definedOrError ( response . sessionHandle ) , this . logger ) ;
162160 }
163161
164- getClient ( ) {
162+ public getClient ( ) {
165163 if ( ! this . client ) {
166164 throw new HiveDriverError ( 'DBSQLClient: client is not initialized' ) ;
167165 }
168166
169167 return this . client ;
170168 }
171169
172- close ( ) : Promise < void > {
173- if ( ! this . connection ) {
174- return Promise . resolve ( ) ;
175- }
170+ public async close ( ) : Promise < void > {
171+ if ( this . connection ) {
172+ const thriftConnection = this . connection . getConnection ( ) ;
176173
177- const thriftConnection = this . connection . getConnection ( ) ;
174+ if ( typeof thriftConnection . end === 'function' ) {
175+ this . connection . getConnection ( ) . end ( ) ;
176+ }
178177
179- if ( typeof thriftConnection . end === 'function' ) {
180- this . connection . getConnection ( ) . end ( ) ;
178+ this . connection = null ;
181179 }
182-
183- return Promise . resolve ( ) ;
184180 }
185181}
0 commit comments