Class Spanner

[Cloud Spanner](https://cloud.google.com/spanner) is a highly scalable, transactional, managed, NewSQL database service. Cloud Spanner solves the need for a horizontally-scaling database with consistent global transaction and SQL semantics. With Cloud Spanner you don't need to choose between consistency and horizontal scaling — you get both.

[Cloud Spanner Documentation](https://cloud.google.com/spanner/docs) [Cloud Spanner Concepts](https://cloud.google.com/spanner/docs/concepts)

Inheritance

GrpcService > Spanner

Package

@google-cloud/spanner!

Constructors

(constructor)(options)

constructor(options?: SpannerOptions);

Constructs a new instance of the Spanner class

Parameter
TypeNameDescription
SpannerOptionsoptions

Properties

auth

auth: GoogleAuth;
Property Value
TypeDescription
GoogleAuth

clients_

clients_: Map<string, {}>;
Property Value
TypeDescription
Map<string, {}>

COMMIT_TIMESTAMP

static COMMIT_TIMESTAMP: string;

Placeholder used to auto populate a column with the commit timestamp. This can only be used for timestamp columns that have set the option "(allow_commit_timestamp=true)" in the schema.

{string}

Property Value
TypeDescription
string

instances_

instances_: Map<string, Instance>;
Property Value
TypeDescription
Map<string, Instance>

options

options: GoogleAuthOptions;
Property Value
TypeDescription
GoogleAuthOptions

projectFormattedName_

projectFormattedName_: string;
Property Value
TypeDescription
string

projectIdReplaced_

projectIdReplaced_: boolean;
Property Value
TypeDescription
boolean

resourceHeader_

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

Methods

close()

close(): void;

Closes this Spanner client and cleans up all resources used by it.

Returns
TypeDescription
void

createInstance(name, config)

createInstance(name: string, config: CreateInstanceRequest): Promise<CreateInstanceResponse>;
Parameters
TypeNameDescription
stringname
CreateInstanceRequestconfig
Returns
TypeDescription
Promise<CreateInstanceResponse>

createInstance(name, config, callback)

createInstance(name: string, config: CreateInstanceRequest, callback: CreateInstanceCallback): void;
Parameters
TypeNameDescription
stringname
CreateInstanceRequestconfig
CreateInstanceCallbackcallback
Returns
TypeDescription
void

date(dateString)

static date(dateString?: string): any;
Parameter
TypeNameDescription
stringdateString
Returns
TypeDescription
any

date(year, month, date)

static date(year: number, month: number, date: number): any;
Parameters
TypeNameDescription
numberyear
numbermonth
numberdate
Returns
TypeDescription
any

float(value)

static float(value: any): Float;

Helper function to get a Cloud Spanner Float64 object.

Parameter
TypeNameDescription
anyvalue

The float as a number or string.

Returns
TypeDescription
Float

{Float}

getInstanceConfig(name)

getInstanceConfig(name: string): Promise<GetInstanceConfigResponse>;
Parameter
TypeNameDescription
stringname
Returns
TypeDescription
Promise<GetInstanceConfigResponse>

getInstanceConfig(name, options)

getInstanceConfig(name: string, options: GetInstanceConfigOptions): Promise<GetInstanceConfigResponse>;
Parameters
TypeNameDescription
stringname
GetInstanceConfigOptionsoptions
Returns
TypeDescription
Promise<GetInstanceConfigResponse>

getInstanceConfig(name, callback)

getInstanceConfig(name: string, callback: GetInstanceConfigCallback): void;
Parameters
TypeNameDescription
stringname
GetInstanceConfigCallbackcallback
Returns
TypeDescription
void

getInstanceConfig(name, options, callback)

getInstanceConfig(name: string, options: GetInstanceConfigOptions, callback: GetInstanceConfigCallback): void;
Parameters
TypeNameDescription
stringname
GetInstanceConfigOptionsoptions
GetInstanceConfigCallbackcallback
Returns
TypeDescription
void

getInstanceConfigs(query)

getInstanceConfigs(query?: GetInstanceConfigsOptions): Promise<GetInstanceConfigsResponse>;
Parameter
TypeNameDescription
GetInstanceConfigsOptionsquery
Returns
TypeDescription
Promise<GetInstanceConfigsResponse>

getInstanceConfigs(callback)

getInstanceConfigs(callback: GetInstanceConfigsCallback): void;
Parameter
TypeNameDescription
GetInstanceConfigsCallbackcallback
Returns
TypeDescription
void

getInstanceConfigs(query, callback)

getInstanceConfigs(query: GetInstanceConfigsOptions, callback: GetInstanceConfigsCallback): void;
Parameters
TypeNameDescription
GetInstanceConfigsOptionsquery
GetInstanceConfigsCallbackcallback
Returns
TypeDescription
void

getInstanceConfigsStream(options)

getInstanceConfigsStream(options?: GetInstanceConfigsOptions): NodeJS.ReadableStream;

Get a list of instance configs as a readable object stream.

Wrapper around .

[ListInstanceConfigs API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs)

Spanner#getInstanceConfigsStream

Parameter
TypeNameDescription
GetInstanceConfigsOptionsoptions

Query object for listing instance configs.

Returns
TypeDescription
NodeJS.ReadableStream

{ReadableStream} A readable stream that emits instance configs.

getInstances(options)

getInstances(options?: GetInstancesOptions): Promise<GetInstancesResponse>;
Parameter
TypeNameDescription
GetInstancesOptionsoptions
Returns
TypeDescription
Promise<GetInstancesResponse>

getInstances(callback)

getInstances(callback: GetInstancesCallback): void;
Parameter
TypeNameDescription
GetInstancesCallbackcallback
Returns
TypeDescription
void

getInstances(query, callback)

getInstances(query: GetInstancesOptions, callback: GetInstancesCallback): void;
Parameters
TypeNameDescription
GetInstancesOptionsquery
GetInstancesCallbackcallback
Returns
TypeDescription
void

getInstancesStream(options)

getInstancesStream(options?: GetInstancesOptions): NodeJS.ReadableStream;

Get a list of Instance objects as a readable object stream.

Wrapper around .

[ListInstances API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstances)

Spanner#getInstancesStream

Parameter
TypeNameDescription
GetInstancesOptionsoptions

Query object for listing instances.

Returns
TypeDescription
NodeJS.ReadableStream

{ReadableStream} A readable stream that emits Instance instances.

getSpannerEmulatorHost()

static getSpannerEmulatorHost(): {
        endpoint: string;
        port?: number;
    } | undefined;

Gets the configured Spanner emulator host from an environment variable.

Returns
TypeDescription
{ endpoint: string; port?: number; } | undefined

instance(name)

instance(name: string): Instance;

Get a reference to an Instance object.

Parameter
TypeNameDescription
stringname

The name of the instance.

Returns
TypeDescription
Instance

{Instance} An Instance object.

int(value)

static int(value: any): Int;

Helper function to get a Cloud Spanner Int64 object.

Parameter
TypeNameDescription
anyvalue

The int as a number or string.

Returns
TypeDescription
Int

{Int}

numeric(value)

static numeric(value: any): Numeric;

Helper function to get a Cloud Spanner Numeric object.

Parameter
TypeNameDescription
anyvalue

The numeric value as a string.

Returns
TypeDescription
Numeric

{Numeric}

prepareGapicRequest_(config, callback)

prepareGapicRequest_(config: any, callback: any): void;

Prepare a gapic request. This will cache the GAX client and replace {{projectId}} placeholders, if necessary.

Parameters
TypeNameDescription
anyconfig

Request config

anycallback

Callback function

Returns
TypeDescription
void

request(config, callback)

request(config: any, callback?: any): any;

Funnel all API requests through this method to be sure we have a project ID.

Parameters
TypeNameDescription
anyconfig

Configuration object.

anycallback

Callback function.

Returns
TypeDescription
any

{Promise}

requestStream(config)

requestStream(config: any): any;

Funnel all streaming API requests through this method to be sure we have a project ID.

Parameter
TypeNameDescription
anyconfig

Configuration object.

Returns
TypeDescription
any

{Stream}

struct(value)

static struct(value?: any): Struct;

Helper function to get a Cloud Spanner Struct object.

Parameter
TypeNameDescription
anyvalue

The struct as a JSON object.

Returns
TypeDescription
Struct

{Struct}

timestamp(value)

static timestamp(value?: string | number | p.ITimestamp | PreciseDate): PreciseDate;

Helper function to get a Cloud Spanner Timestamp object.

String timestamps should have a canonical format of YYYY-[M]M-[D]D[( |T)[H]H:[M]M:[S]S[.DDDDDDDDD]]Z

**Timestamp values must be expressed in Zulu time and cannot include a UTC offset.**

https://cloud.google.com/spanner/docs/data-types#timestamp-type

Parameter
TypeNameDescription
string | number | common.ITimestamp | PreciseDatevalue
Returns
TypeDescription
PreciseDate

{external:PreciseDate}