From 547c0bb1808e838ae01acc8fe7d8fc7510bc4a88 Mon Sep 17 00:00:00 2001 From: Alka Trivedi Date: Tue, 9 Jul 2024 21:53:57 +0530 Subject: [PATCH] fix: callback in getDatabaseDialect --- src/database.ts | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/database.ts b/src/database.ts index f89b65839..fb85e053e 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1533,23 +1533,39 @@ class Database extends common.GrpcServiceObject { ): void; async getDatabaseDialect( optionsOrCallback?: CallOptions | GetDatabaseDialectCallback, - cb?: GetDatabaseDialectCallback + callback?: GetDatabaseDialectCallback ): Promise< | EnumKey | undefined > { const gaxOptions = - typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; + typeof optionsOrCallback === 'object' + ? (optionsOrCallback as CallOptions) + : {}; - if ( - this.databaseDialect === 'DATABASE_DIALECT_UNSPECIFIED' || - this.databaseDialect === null || - this.databaseDialect === undefined - ) { - const [metadata] = await this.getMetadata(gaxOptions); - this.databaseDialect = metadata.databaseDialect; + const cb = + typeof optionsOrCallback === 'function' + ? (optionsOrCallback as GetDatabaseDialectCallback) + : callback; + + try { + if ( + this.databaseDialect === 'DATABASE_DIALECT_UNSPECIFIED' || + this.databaseDialect === null || + this.databaseDialect === undefined + ) { + const [metadata] = await this.getMetadata(gaxOptions); + this.databaseDialect = metadata.databaseDialect; + } + if (cb) { + cb(null, this.databaseDialect); + return; + } + return this.databaseDialect || undefined; + } catch (err) { + cb!(err as grpc.ServiceError); + return; } - return this.databaseDialect || undefined; } /** @@ -3665,6 +3681,7 @@ callbackifyAll(Database, { 'delete', 'exists', 'get', + 'getDatabaseDialect', 'getMetadata', 'getSchema', 'getSessions',