Send feedback
Class Database
Stay organized with collections
Save and categorize content based on your preferences.
Version 5.14.0 keyboard_arrow_down
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
Type Name Description Instance instance
string name
SessionPoolConstructor | SessionPoolOptions poolOptions
spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions queryOptions
Properties
Property Value
pool_
pool_ : SessionPoolInterface ;
Property Value
Type Description SessionPoolInterface
queryOptions_
queryOptions_ ?: spannerClient . spanner . v1 . ExecuteSqlRequest . IQueryOptions ;
Property Value
Type Description spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions
request
request : DatabaseRequest ;
Property Value
Type Description DatabaseRequest
resourceHeader_ : {
[ k : string ] : string ;
};
Property Value
Type Description {
[k: string]: string;
}
Methods
_runPartitionedUpdate(session, query, callback)
_runPartitionedUpdate ( session : Session , query : string | ExecuteSqlRequest , callback ?: RunUpdateCallback ) : void | Promise<number> ;
Parameters
Type Name Description Session session
string | ExecuteSqlRequest query
RunUpdateCallback callback
Returns
Type Description void | Promise <number>
batchCreateSessions(options)
batchCreateSessions ( options : number | BatchCreateSessionsOptions ) : Promise<BatchCreateSessionsResponse> ;
Parameter
Type Name Description number | BatchCreateSessionsOptions options
Returns
Type Description Promise <BatchCreateSessionsResponse >
batchCreateSessions(options, callback)
batchCreateSessions ( options : number | BatchCreateSessionsOptions , callback : BatchCreateSessionsCallback ) : void ;
Parameters
Type Name Description number | BatchCreateSessionsOptions options
BatchCreateSessionsCallback callback
Returns
batchTransaction(identifier, options)
batchTransaction ( identifier : TransactionIdentifier , options ?: TimestampBounds ) : BatchTransaction ;
Get a reference to a object.
to generate an identifier.
Parameters
Returns
Type Description BatchTransaction {BatchTransaction} A batch transaction object.
close(callback)
close ( callback : SessionPoolCloseCallback ) : void ;
Parameter
Type Name Description SessionPoolCloseCallback callback
Returns
close()
close () : Promise<DatabaseCloseResponse> ;
Returns
Type Description Promise <DatabaseCloseResponse >
createBatchTransaction(options)
createBatchTransaction ( options ?: TimestampBounds ) : Promise<CreateBatchTransactionResponse> ;
Parameter
Type Name Description TimestampBounds options
Returns
Type Description Promise <CreateBatchTransactionResponse >
createBatchTransaction(callback)
createBatchTransaction ( callback : CreateBatchTransactionCallback ) : void ;
Parameter
Type Name Description CreateBatchTransactionCallback callback
Returns
createBatchTransaction(options, callback)
createBatchTransaction ( options : TimestampBounds , callback : CreateBatchTransactionCallback ) : void ;
Parameters
Type Name Description TimestampBounds options
CreateBatchTransactionCallback callback
Returns
createSession(options)
createSession ( options : CreateSessionOptions ) : Promise<CreateSessionResponse> ;
Parameter
Type Name Description CreateSessionOptions options
Returns
Type Description Promise <CreateSessionResponse >
createSession(callback)
createSession ( callback : CreateSessionCallback ) : void ;
Parameter
Type Name Description CreateSessionCallback callback
Returns
createSession(options, callback)
createSession ( options : CreateSessionOptions , callback : CreateSessionCallback ) : void ;
Parameters
Type Name Description CreateSessionOptions options
CreateSessionCallback callback
Returns
createTable(schema, gaxOptions)
createTable ( schema : Schema , gaxOptions ?: CallOptions ) : Promise<CreateTableResponse> ;
Parameters
Type Name Description Schema schema
CallOptions gaxOptions
Returns
Type Description Promise <CreateTableResponse >
createTable(schema, callback)
createTable ( schema : Schema , callback : CreateTableCallback ) : void ;
Parameters
Type Name Description Schema schema
CreateTableCallback callback
Returns
createTable(schema, gaxOptions, callback)
createTable ( schema : Schema , gaxOptions : CallOptions , callback : CreateTableCallback ) : void ;
Parameters
Type Name Description Schema schema
CallOptions gaxOptions
CreateTableCallback callback
Returns
delete(gaxOptions)
delete ( gaxOptions ?: CallOptions ) : Promise<DatabaseDeleteResponse> ;
Parameter
Type Name Description CallOptions gaxOptions
Returns
Type Description Promise <DatabaseDeleteResponse >
delete(callback)
delete ( callback : DatabaseDeleteCallback ) : void ;
Parameter
Type Name Description DatabaseDeleteCallback callback
Returns
delete(gaxOptions, callback)
delete ( gaxOptions : CallOptions , callback : DatabaseDeleteCallback ) : void ;
Parameters
Type Name Description CallOptions gaxOptions
DatabaseDeleteCallback callback
Returns
exists(gaxOptions)
exists ( gaxOptions ?: CallOptions ) : Promise <[ boolean ]>;
Parameter
Type Name Description CallOptions gaxOptions
Returns
Type Description Promise <[boolean]>
exists(callback)
exists ( callback : ExistsCallback ) : void ;
Parameter
Type Name Description ExistsCallback callback
Returns
exists(gaxOptions, callback)
exists ( gaxOptions : CallOptions , callback : ExistsCallback ) : void ;
Parameters
Type Name Description CallOptions gaxOptions
ExistsCallback callback
Returns
static formatName_ ( instanceName : string , name : string ) : string ;
Format the database name to include the instance name.
Parameters
Type Name Description string instanceName
The formatted instance name.
string name
The table name.
Returns
Type Description string {string}
get(options)
get ( options ?: GetDatabaseConfig ) : Promise<DatabaseResponse> ;
Parameter
Type Name Description GetDatabaseConfig options
Returns
Type Description Promise <DatabaseResponse >
get(callback)
get ( callback : DatabaseCallback ) : void ;
Parameter
Type Name Description DatabaseCallback callback
Returns
get(options, callback)
get ( options : GetDatabaseConfig , callback : DatabaseCallback ) : void ;
Parameters
Type Name Description GetDatabaseConfig options
DatabaseCallback callback
Returns
getEnvironmentQueryOptions()
static getEnvironmentQueryOptions () : databaseAdmin . spanner . v1 . ExecuteSqlRequest . IQueryOptions ;
Returns
Type Description spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions
getMetadata ( gaxOptions ?: CallOptions ) : Promise<GetDatabaseMetadataResponse> ;
Parameter
Type Name Description CallOptions gaxOptions
Returns
Type Description Promise <GetDatabaseMetadataResponse >
getMetadata ( callback : GetDatabaseMetadataCallback ) : void ;
Parameter
Type Name Description GetDatabaseMetadataCallback callback
Returns
getMetadata ( gaxOptions : CallOptions , callback : GetDatabaseMetadataCallback ) : void ;
Parameters
Type Name Description CallOptions gaxOptions
GetDatabaseMetadataCallback callback
Returns
getOperations(options)
getOperations ( options ?: GetDatabaseOperationsOptions ) : Promise<GetDatabaseOperationsResponse> ;
Parameter
Type Name Description GetDatabaseOperationsOptions options
Returns
Type Description Promise <GetDatabaseOperationsResponse >
getOperations(callback)
getOperations ( callback : GetDatabaseOperationsCallback ) : void ;
Parameter
Type Name Description GetDatabaseOperationsCallback callback
Returns
getOperations(options, callback)
getOperations ( options : GetDatabaseOperationsOptions , callback : GetDatabaseOperationsCallback ) : void ;
Parameters
Type Name Description GetDatabaseOperationsOptions options
GetDatabaseOperationsCallback callback
Returns
getRestoreInfo(options)
getRestoreInfo ( options ?: CallOptions ) : Promise<IRestoreInfoTranslatedEnum | undefined >;
Parameter
Type Name Description CallOptions options
Returns
Type Description Promise <IRestoreInfoTranslatedEnum | undefined>
getRestoreInfo(callback)
getRestoreInfo ( callback : GetRestoreInfoCallback ) : void ;
Parameter
Type Name Description GetRestoreInfoCallback callback
Returns
getRestoreInfo(options, callback)
getRestoreInfo ( options : CallOptions , callback : GetRestoreInfoCallback ) : void ;
Parameters
Type Name Description CallOptions options
GetRestoreInfoCallback callback
Returns
getSchema(options)
getSchema ( options ?: CallOptions ) : Promise<GetSchemaResponse> ;
Parameter
Type Name Description CallOptions options
Returns
Type Description Promise <GetSchemaResponse >
getSchema(callback)
getSchema ( callback : GetSchemaCallback ) : void ;
Parameter
Type Name Description GetSchemaCallback callback
Returns
getSchema(options, callback)
getSchema ( options : CallOptions , callback : GetSchemaCallback ) : void ;
Parameters
Type Name Description CallOptions options
GetSchemaCallback callback
Returns
getSessions(options)
getSessions ( options ?: GetSessionsOptions ) : Promise<GetSessionsResponse> ;
Parameter
Type Name Description GetSessionsOptions options
Returns
Type Description Promise <GetSessionsResponse >
getSessions(callback)
getSessions ( callback : GetSessionsCallback ) : void ;
Parameter
Type Name Description GetSessionsCallback callback
Returns
getSessions(options, callback)
getSessions ( options : GetSessionsOptions , callback : GetSessionsCallback ) : void ;
Parameters
Type Name Description GetSessionsOptions options
GetSessionsCallback callback
Returns
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
Type Name Description GetSessionsOptions options
Options object for listing sessions.
Returns
Type Description NodeJS.ReadableStream {ReadableStream} A readable stream that emits Session instances.
getSnapshot(options)
getSnapshot ( options ?: TimestampBounds ) : Promise <[ Snapshot ]>;
Parameter
Type Name Description TimestampBounds options
Returns
getSnapshot(callback)
getSnapshot ( callback : GetSnapshotCallback ) : void ;
Parameter
Type Name Description GetSnapshotCallback callback
Returns
getSnapshot(options, callback)
getSnapshot ( options : TimestampBounds , callback : GetSnapshotCallback ) : void ;
Parameters
Type Name Description TimestampBounds options
GetSnapshotCallback callback
Returns
getState(options)
getState ( options ?: CallOptions ) : Promise<EnumKey<typeof databaseAdmin . spanner . admin . database . v1 . Database . State > | undefined >;
Parameter
Type Name Description CallOptions options
Returns
Type Description Promise <EnumKey <typeof google.spanner.admin.database.v1.Database.State > | undefined>
getState(callback)
getState ( callback : GetStateCallback ) : void ;
Parameter
Type Name Description GetStateCallback callback
Returns
getState(options, callback)
getState ( options : CallOptions , callback : GetStateCallback ) : void ;
Parameters
Type Name Description CallOptions options
GetStateCallback callback
Returns
getTransaction()
getTransaction () : Promise <[ Transaction ]>;
Returns
getTransaction(callback)
getTransaction ( callback : GetTransactionCallback ) : void ;
Parameter
Type Name Description GetTransactionCallback callback
Returns
makePooledRequest_(config)
makePooledRequest_ ( config : RequestConfig ) : Promise<Session> ;
Parameter
Returns
makePooledRequest_(config, callback)
makePooledRequest_ ( config : RequestConfig , callback : PoolRequestCallback ) : void ;
Parameters
Type Name Description RequestConfig config
PoolRequestCallback callback
Returns
makePooledStreamingRequest_(config)
makePooledStreamingRequest_ ( config : RequestConfig ) : Readable ;
Make an API request as a stream, first assuring an active session is used.
Parameter
Returns
Type Description Readable {Stream}
restore(backupPath)
restore ( backupPath : string ) : Promise<RestoreDatabaseResponse> ;
Parameter
Type Name Description string backupPath
Returns
Type Description Promise <RestoreDatabaseResponse >
restore(backupPath, options)
restore ( backupPath : string , options ?: RestoreOptions | CallOptions ) : Promise<RestoreDatabaseResponse> ;
Parameters
Type Name Description string backupPath
RestoreOptions | CallOptions options
Returns
Type Description Promise <RestoreDatabaseResponse >
restore(backupPath, callback)
restore ( backupPath : string , callback : RestoreDatabaseCallback ) : void ;
Parameters
Type Name Description string backupPath
RestoreDatabaseCallback callback
Returns
restore(backupPath, options, callback)
restore ( backupPath : string , options : RestoreOptions | CallOptions , callback : RestoreDatabaseCallback ) : void ;
Parameters
Type Name Description string backupPath
RestoreOptions | CallOptions options
RestoreDatabaseCallback callback
Returns
run(query)
run ( query : string | ExecuteSqlRequest ) : Promise<RunResponse> ;
Parameter
Type Name Description string | ExecuteSqlRequest query
Returns
Type Description Promise <RunResponse >
run(query, options)
run ( query : string | ExecuteSqlRequest , options ?: TimestampBounds ) : Promise<RunResponse> ;
Parameters
Type Name Description string | ExecuteSqlRequest query
TimestampBounds options
Returns
Type Description Promise <RunResponse >
run(query, callback)
run ( query : string | ExecuteSqlRequest , callback : RunCallback ) : void ;
Parameters
Type Name Description string | ExecuteSqlRequest query
RunCallback callback
Returns
run(query, options, callback)
run ( query : string | ExecuteSqlRequest , options : TimestampBounds , callback : RunCallback ) : void ;
Parameters
Type Name Description string | ExecuteSqlRequest query
TimestampBounds options
RunCallback callback
Returns
runPartitionedUpdate(query)
runPartitionedUpdate ( query : string | ExecuteSqlRequest ) : Promise <[ number ]>;
Parameter
Type Name Description string | ExecuteSqlRequest query
Returns
Type Description Promise <[number]>
runPartitionedUpdate(query, callback)
runPartitionedUpdate ( query : string | ExecuteSqlRequest , callback ?: RunUpdateCallback ) : void ;
Parameters
Type Name Description string | ExecuteSqlRequest query
RunUpdateCallback callback
Returns
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
Type Name Description string | ExecuteSqlRequest query
A SQL query or object.
TimestampBounds options
Snapshot timestamp bounds.
Returns
Type Description PartialResultStream {PartialResultStream} A readable stream that emits rows.
runTransaction(runFn)
runTransaction ( runFn : RunTransactionCallback ) : void ;
Parameter
Type Name Description RunTransactionCallback runFn
Returns
runTransaction(options, runFn)
runTransaction ( options : RunTransactionOptions , runFn : RunTransactionCallback ) : void ;
Parameters
Type Name Description RunTransactionOptions options
RunTransactionCallback runFn
Returns
runTransactionAsync(runFn)
runTransactionAsync<T = {}>( runFn : AsyncRunTransactionCallback<T> ) : Promise<T> ;
Parameter
Type Name Description AsyncRunTransactionCallback <T>runFn
Returns
Type Description Promise <T>
Type Parameter
runTransactionAsync(options, runFn)
runTransactionAsync<T = {}>( options : RunTransactionOptions , runFn : AsyncRunTransactionCallback<T> ) : Promise<T> ;
Parameters
Type Name Description RunTransactionOptions options
AsyncRunTransactionCallback <T>runFn
Returns
Type Description Promise <T>
Type Parameter
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
Type Name Description string name
The name of the session. If not provided, it is assumed you are going to create it.
Returns
Type Description Session {Session} A Session object.
table(name)
table ( name : string ) : Table ;
Get a reference to a Table object.
Parameter
Type Name Description string name
The name of the table. {Table} A Table object.
Returns
updateSchema(statements, gaxOptions)
updateSchema ( statements : Schema , gaxOptions ?: CallOptions ) : Promise<UpdateSchemaResponse> ;
Parameters
Type Name Description Schema statements
CallOptions gaxOptions
Returns
Type Description Promise <UpdateSchemaResponse >
updateSchema(statements, callback)
updateSchema ( statements : Schema , callback : UpdateSchemaCallback ) : void ;
Parameters
Type Name Description Schema statements
UpdateSchemaCallback callback
Returns
updateSchema(statements, gaxOptions, callback)
updateSchema ( statements : Schema , gaxOptions : CallOptions , callback : UpdateSchemaCallback ) : void ;
Parameters
Type Name Description Schema statements
CallOptions gaxOptions
UpdateSchemaCallback callback
Returns
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-11-19 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-19 UTC."],[],[]]