From 7e4a8e9ad4f785b15b68aaa06b6480098d7995ba Mon Sep 17 00:00:00 2001 From: alkatrivedi <58396306+alkatrivedi@users.noreply.github.com> Date: Fri, 19 Jul 2024 06:35:53 +0000 Subject: [PATCH] fix: callback in getDatabaseDialect (#2078) --- 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',