Class Database

Create a Database object to interact with a Cloud Spanner database.

Inheritance

common.GrpcServiceObject > Database

Package

@google-cloud/spanner!

Constructors

(constructor)(instance, name, poolOptions, queryOptions)

constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);

Constructs a new instance of the Database class

Parameters
TypeNameDescription
Instanceinstance
stringname
SessionPoolConstructor | SessionPoolOptionspoolOptions
spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptionsqueryOptions

Properties

formattedName_

formattedName_: string;
Property Value
TypeDescription
string

pool_

pool_: SessionPoolInterface;
Property Value
TypeDescription
SessionPoolInterface

queryOptions_

queryOptions_?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions;
Property Value
TypeDescription
spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions

request

request: DatabaseRequest;
Property Value
TypeDescription
DatabaseRequest

resourceHeader_

resourceHeader_: {
        [k: string]: string;
    };
Property Value
TypeDescription
{ [k: string]: string; }

Methods

_runPartitionedUpdate(session, query, callback)

_runPartitionedUpdate(session: Session, query: string | ExecuteSqlRequest, callback?: RunUpdateCallback): void | Promise<number>;
Parameters
TypeNameDescription
Sessionsession
string | ExecuteSqlRequestquery
RunUpdateCallbackcallback
Returns
TypeDescription
void | Promise<number>

batchCreateSessions(options)

batchCreateSessions(options: number | BatchCreateSessionsOptions): Promise<BatchCreateSessionsResponse>;
Parameter
TypeNameDescription
number | BatchCreateSessionsOptionsoptions
Returns
TypeDescription
Promise<BatchCreateSessionsResponse>

batchCreateSessions(options, callback)

batchCreateSessions(options: number | BatchCreateSessionsOptions, callback: BatchCreateSessionsCallback): void;
Parameters
TypeNameDescription
number | BatchCreateSessionsOptionsoptions
BatchCreateSessionsCallbackcallback
Returns
TypeDescription
void

batchTransaction(identifier, options)

batchTransaction(identifier: TransactionIdentifier, options?: TimestampBounds): BatchTransaction;

Get a reference to a object.

to generate an identifier.

Parameters
TypeNameDescription
TransactionIdentifieridentifier

The transaction identifier.

TimestampBoundsoptions

[Transaction options](https://cloud.google.com/spanner/docs/timestamp-bounds).

Returns
TypeDescription
BatchTransaction

{BatchTransaction} A batch transaction object.

close(callback)

close(callback: SessionPoolCloseCallback): void;
Parameter
TypeNameDescription
SessionPoolCloseCallbackcallback
Returns
TypeDescription
void

close()

close(): Promise<DatabaseCloseResponse>;
Returns
TypeDescription
Promise<DatabaseCloseResponse>

createBatchTransaction(options)

createBatchTransaction(options?: TimestampBounds): Promise<CreateBatchTransactionResponse>;
Parameter
TypeNameDescription
TimestampBoundsoptions
Returns
TypeDescription
Promise<CreateBatchTransactionResponse>

createBatchTransaction(callback)

createBatchTransaction(callback: CreateBatchTransactionCallback): void;
Parameter
TypeNameDescription
CreateBatchTransactionCallbackcallback
Returns
TypeDescription
void

createBatchTransaction(options, callback)

createBatchTransaction(options: TimestampBounds, callback: CreateBatchTransactionCallback): void;
Parameters
TypeNameDescription
TimestampBoundsoptions
CreateBatchTransactionCallbackcallback
Returns
TypeDescription
void

createSession(options)

createSession(options: CreateSessionOptions): Promise<CreateSessionResponse>;
Parameter
TypeNameDescription
CreateSessionOptionsoptions
Returns
TypeDescription
Promise<CreateSessionResponse>

createSession(callback)

createSession(callback: CreateSessionCallback): void;
Parameter
TypeNameDescription
CreateSessionCallbackcallback
Returns
TypeDescription
void

createSession(options, callback)

createSession(options: CreateSessionOptions, callback: CreateSessionCallback): void;
Parameters
TypeNameDescription
CreateSessionOptionsoptions
CreateSessionCallbackcallback
Returns
TypeDescription
void

createTable(schema, gaxOptions)

createTable(schema: Schema, gaxOptions?: CallOptions): Promise<CreateTableResponse>;
Parameters
TypeNameDescription
Schemaschema
CallOptionsgaxOptions
Returns
TypeDescription
Promise<CreateTableResponse>

createTable(schema, callback)

createTable(schema: Schema, callback: CreateTableCallback): void;
Parameters
TypeNameDescription
Schemaschema
CreateTableCallbackcallback
Returns
TypeDescription
void

createTable(schema, gaxOptions, callback)

createTable(schema: Schema, gaxOptions: CallOptions, callback: CreateTableCallback): void;
Parameters
TypeNameDescription
Schemaschema
CallOptionsgaxOptions
CreateTableCallbackcallback
Returns
TypeDescription
void

delete(gaxOptions)

delete(gaxOptions?: CallOptions): Promise<DatabaseDeleteResponse>;
Parameter
TypeNameDescription
CallOptionsgaxOptions
Returns
TypeDescription
Promise<DatabaseDeleteResponse>

delete(callback)

delete(callback: DatabaseDeleteCallback): void;
Parameter
TypeNameDescription
DatabaseDeleteCallbackcallback
Returns
TypeDescription
void

delete(gaxOptions, callback)

delete(gaxOptions: CallOptions, callback: DatabaseDeleteCallback): void;
Parameters
TypeNameDescription
CallOptionsgaxOptions
DatabaseDeleteCallbackcallback
Returns
TypeDescription
void

exists(gaxOptions)

exists(gaxOptions?: CallOptions): Promise<[boolean]>;
Parameter
TypeNameDescription
CallOptionsgaxOptions
Returns
TypeDescription
Promise<[boolean]>

exists(callback)

exists(callback: ExistsCallback): void;
Parameter
TypeNameDescription
ExistsCallbackcallback
Returns
TypeDescription
void

exists(gaxOptions, callback)

exists(gaxOptions: CallOptions, callback: ExistsCallback): void;
Parameters
TypeNameDescription
CallOptionsgaxOptions
ExistsCallbackcallback
Returns
TypeDescription
void

formatName_(instanceName, name)

static formatName_(instanceName: string, name: string): string;

Format the database name to include the instance name.

Parameters
TypeNameDescription
stringinstanceName

The formatted instance name.

stringname

The table name.

Returns
TypeDescription
string

{string}

get(options)

get(options?: GetDatabaseConfig): Promise<DatabaseResponse>;
Parameter
TypeNameDescription
GetDatabaseConfigoptions
Returns
TypeDescription
Promise<DatabaseResponse>

get(callback)

get(callback: DatabaseCallback): void;
Parameter
TypeNameDescription
DatabaseCallbackcallback
Returns
TypeDescription
void

get(options, callback)

get(options: GetDatabaseConfig, callback: DatabaseCallback): void;
Parameters
TypeNameDescription
GetDatabaseConfigoptions
DatabaseCallbackcallback
Returns
TypeDescription
void

getEnvironmentQueryOptions()

static getEnvironmentQueryOptions(): databaseAdmin.spanner.v1.ExecuteSqlRequest.IQueryOptions;
Returns
TypeDescription
spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions

getMetadata(gaxOptions)

getMetadata(gaxOptions?: CallOptions): Promise<GetDatabaseMetadataResponse>;
Parameter
TypeNameDescription
CallOptionsgaxOptions
Returns
TypeDescription
Promise<GetDatabaseMetadataResponse>

getMetadata(callback)

getMetadata(callback: GetDatabaseMetadataCallback): void;
Parameter
TypeNameDescription
GetDatabaseMetadataCallbackcallback
Returns
TypeDescription
void

getMetadata(gaxOptions, callback)

getMetadata(gaxOptions: CallOptions, callback: GetDatabaseMetadataCallback): void;
Parameters
TypeNameDescription
CallOptionsgaxOptions
GetDatabaseMetadataCallbackcallback
Returns
TypeDescription
void

getOperations(options)

getOperations(options?: GetDatabaseOperationsOptions): Promise<GetDatabaseOperationsResponse>;
Parameter
TypeNameDescription
GetDatabaseOperationsOptionsoptions
Returns
TypeDescription
Promise<GetDatabaseOperationsResponse>

getOperations(callback)

getOperations(callback: GetDatabaseOperationsCallback): void;
Parameter
TypeNameDescription
GetDatabaseOperationsCallbackcallback
Returns
TypeDescription
void

getOperations(options, callback)

getOperations(options: GetDatabaseOperationsOptions, callback: GetDatabaseOperationsCallback): void;
Parameters
TypeNameDescription
GetDatabaseOperationsOptionsoptions
GetDatabaseOperationsCallbackcallback
Returns
TypeDescription
void

getRestoreInfo(options)

getRestoreInfo(options?: CallOptions): Promise<IRestoreInfoTranslatedEnum | undefined>;
Parameter
TypeNameDescription
CallOptionsoptions
Returns
TypeDescription
Promise<IRestoreInfoTranslatedEnum | undefined>

getRestoreInfo(callback)

getRestoreInfo(callback: GetRestoreInfoCallback): void;
Parameter
TypeNameDescription
GetRestoreInfoCallbackcallback
Returns
TypeDescription
void

getRestoreInfo(options, callback)

getRestoreInfo(options: CallOptions, callback: GetRestoreInfoCallback): void;
Parameters
TypeNameDescription
CallOptionsoptions
GetRestoreInfoCallbackcallback
Returns
TypeDescription
void

getSchema(options)

getSchema(options?: CallOptions): Promise<GetSchemaResponse>;
Parameter
TypeNameDescription
CallOptionsoptions
Returns
TypeDescription
Promise<GetSchemaResponse>

getSchema(callback)

getSchema(callback: GetSchemaCallback): void;
Parameter
TypeNameDescription
GetSchemaCallbackcallback
Returns
TypeDescription
void

getSchema(options, callback)

getSchema(options: CallOptions, callback: GetSchemaCallback): void;
Parameters
TypeNameDescription
CallOptionsoptions
GetSchemaCallbackcallback
Returns
TypeDescription
void

getSessions(options)

getSessions(options?: GetSessionsOptions): Promise<GetSessionsResponse>;
Parameter
TypeNameDescription
GetSessionsOptionsoptions
Returns
TypeDescription
Promise<GetSessionsResponse>

getSessions(callback)

getSessions(callback: GetSessionsCallback): void;
Parameter
TypeNameDescription
GetSessionsCallbackcallback
Returns
TypeDescription
void

getSessions(options, callback)

getSessions(options: GetSessionsOptions, callback: GetSessionsCallback): void;
Parameters
TypeNameDescription
GetSessionsOptionsoptions
GetSessionsCallbackcallback
Returns
TypeDescription
void

getSessionsStream(options)

getSessionsStream(options?: GetSessionsOptions): NodeJS.ReadableStream;

Get a list of sessions as a readable object stream.

Wrapper around

[ListSessions API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ListSessions)

Spanner#getSessionsStream

Parameter
TypeNameDescription
GetSessionsOptionsoptions

Options object for listing sessions.

Returns
TypeDescription
NodeJS.ReadableStream

{ReadableStream} A readable stream that emits Session instances.

getSnapshot(options)

getSnapshot(options?: TimestampBounds): Promise<[Snapshot]>;
Parameter
TypeNameDescription
TimestampBoundsoptions
Returns
TypeDescription
Promise<[Snapshot]>

getSnapshot(callback)

getSnapshot(callback: GetSnapshotCallback): void;
Parameter
TypeNameDescription
GetSnapshotCallbackcallback
Returns
TypeDescription
void

getSnapshot(options, callback)

getSnapshot(options: TimestampBounds, callback: GetSnapshotCallback): void;
Parameters
TypeNameDescription
TimestampBoundsoptions
GetSnapshotCallbackcallback
Returns
TypeDescription
void

getState(options)

getState(options?: CallOptions): Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State> | undefined>;
Parameter
TypeNameDescription
CallOptionsoptions
Returns
TypeDescription
Promise<EnumKey<typeof google.spanner.admin.database.v1.Database.State> | undefined>

getState(callback)

getState(callback: GetStateCallback): void;
Parameter
TypeNameDescription
GetStateCallbackcallback
Returns
TypeDescription
void

getState(options, callback)

getState(options: CallOptions, callback: GetStateCallback): void;
Parameters
TypeNameDescription
CallOptionsoptions
GetStateCallbackcallback
Returns
TypeDescription
void

getTransaction()

getTransaction(): Promise<[Transaction]>;
Returns
TypeDescription
Promise<[Transaction]>

getTransaction(callback)

getTransaction(callback: GetTransactionCallback): void;
Parameter
TypeNameDescription
GetTransactionCallbackcallback
Returns
TypeDescription
void

makePooledRequest_(config)

makePooledRequest_(config: RequestConfig): Promise<Session>;
Parameter
TypeNameDescription
RequestConfigconfig
Returns
TypeDescription
Promise<Session>

makePooledRequest_(config, callback)

makePooledRequest_(config: RequestConfig, callback: PoolRequestCallback): void;
Parameters
TypeNameDescription
RequestConfigconfig
PoolRequestCallbackcallback
Returns
TypeDescription
void

makePooledStreamingRequest_(config)

makePooledStreamingRequest_(config: RequestConfig): Readable;

Make an API request as a stream, first assuring an active session is used.

Parameter
TypeNameDescription
RequestConfigconfig

Request config

Returns
TypeDescription
Readable

{Stream}

restore(backupPath)

restore(backupPath: string): Promise<RestoreDatabaseResponse>;
Parameter
TypeNameDescription
stringbackupPath
Returns
TypeDescription
Promise<RestoreDatabaseResponse>

restore(backupPath, options)

restore(backupPath: string, options?: RestoreOptions | CallOptions): Promise<RestoreDatabaseResponse>;
Parameters
TypeNameDescription
stringbackupPath
RestoreOptions | CallOptionsoptions
Returns
TypeDescription
Promise<RestoreDatabaseResponse>

restore(backupPath, callback)

restore(backupPath: string, callback: RestoreDatabaseCallback): void;
Parameters
TypeNameDescription
stringbackupPath
RestoreDatabaseCallbackcallback
Returns
TypeDescription
void

restore(backupPath, options, callback)

restore(backupPath: string, options: RestoreOptions | CallOptions, callback: RestoreDatabaseCallback): void;
Parameters
TypeNameDescription
stringbackupPath
RestoreOptions | CallOptionsoptions
RestoreDatabaseCallbackcallback
Returns
TypeDescription
void

run(query)

run(query: string | ExecuteSqlRequest): Promise<RunResponse>;
Parameter
TypeNameDescription
string | ExecuteSqlRequestquery
Returns
TypeDescription
Promise<RunResponse>

run(query, options)

run(query: string | ExecuteSqlRequest, options?: TimestampBounds): Promise<RunResponse>;
Parameters
TypeNameDescription
string | ExecuteSqlRequestquery
TimestampBoundsoptions
Returns
TypeDescription
Promise<RunResponse>

run(query, callback)

run(query: string | ExecuteSqlRequest, callback: RunCallback): void;
Parameters
TypeNameDescription
string | ExecuteSqlRequestquery
RunCallbackcallback
Returns
TypeDescription
void

run(query, options, callback)

run(query: string | ExecuteSqlRequest, options: TimestampBounds, callback: RunCallback): void;
Parameters
TypeNameDescription
string | ExecuteSqlRequestquery
TimestampBoundsoptions
RunCallbackcallback
Returns
TypeDescription
void

runPartitionedUpdate(query)

runPartitionedUpdate(query: string | ExecuteSqlRequest): Promise<[number]>;
Parameter
TypeNameDescription
string | ExecuteSqlRequestquery
Returns
TypeDescription
Promise<[number]>

runPartitionedUpdate(query, callback)

runPartitionedUpdate(query: string | ExecuteSqlRequest, callback?: RunUpdateCallback): void;
Parameters
TypeNameDescription
string | ExecuteSqlRequestquery
RunUpdateCallbackcallback
Returns
TypeDescription
void

runStream(query, options)

runStream(query: string | ExecuteSqlRequest, options?: TimestampBounds): PartialResultStream;

Create a readable object stream to receive resulting rows from a SQL statement.

Wrapper around .

[Query Syntax](https://cloud.google.com/spanner/docs/query-syntax) [ExecuteSql API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ExecuteSql)

PartialResultStream#response

Parameters
TypeNameDescription
string | ExecuteSqlRequestquery

A SQL query or object.

TimestampBoundsoptions

Snapshot timestamp bounds.

Returns
TypeDescription
PartialResultStream

{PartialResultStream} A readable stream that emits rows.

runTransaction(runFn)

runTransaction(runFn: RunTransactionCallback): void;
Parameter
TypeNameDescription
RunTransactionCallbackrunFn
Returns
TypeDescription
void

runTransaction(options, runFn)

runTransaction(options: RunTransactionOptions, runFn: RunTransactionCallback): void;
Parameters
TypeNameDescription
RunTransactionOptionsoptions
RunTransactionCallbackrunFn
Returns
TypeDescription
void

runTransactionAsync(runFn)

runTransactionAsync<T = {}>(runFn: AsyncRunTransactionCallback<T>): Promise<T>;
Parameter
TypeNameDescription
AsyncRunTransactionCallback<T>runFn
Returns
TypeDescription
Promise<T>
Type Parameter
NameDescription
T

runTransactionAsync(options, runFn)

runTransactionAsync<T = {}>(options: RunTransactionOptions, runFn: AsyncRunTransactionCallback<T>): Promise<T>;
Parameters
TypeNameDescription
RunTransactionOptionsoptions
AsyncRunTransactionCallback<T>runFn
Returns
TypeDescription
Promise<T>
Type Parameter
NameDescription
T

session(name)

session(name?: string): Session;

Create a Session object.

It is unlikely you will need to interact with sessions directly. By default, sessions are created and utilized for maximum performance automatically.

Parameter
TypeNameDescription
stringname

The name of the session. If not provided, it is assumed you are going to create it.

Returns
TypeDescription
Session

{Session} A Session object.

table(name)

table(name: string): Table;

Get a reference to a Table object.

Parameter
TypeNameDescription
stringname

The name of the table. {Table} A Table object.

Returns
TypeDescription
Table

updateSchema(statements, gaxOptions)

updateSchema(statements: Schema, gaxOptions?: CallOptions): Promise<UpdateSchemaResponse>;
Parameters
TypeNameDescription
Schemastatements
CallOptionsgaxOptions
Returns
TypeDescription
Promise<UpdateSchemaResponse>

updateSchema(statements, callback)

updateSchema(statements: Schema, callback: UpdateSchemaCallback): void;
Parameters
TypeNameDescription
Schemastatements
UpdateSchemaCallbackcallback
Returns
TypeDescription
void

updateSchema(statements, gaxOptions, callback)

updateSchema(statements: Schema, gaxOptions: CallOptions, callback: UpdateSchemaCallback): void;
Parameters
TypeNameDescription
Schemastatements
CallOptionsgaxOptions
UpdateSchemaCallbackcallback
Returns
TypeDescription
void