This transaction type provides guaranteed consistency across several reads, but does not allow writes. Snapshot read-only transactions can be configured to read at timestamps in the past.
When finished with the Snapshot, call to release the underlying Session. Failure to do so can result in a Session leak.
**This object is created and returned from .**
[Timestamp Bounds API Documentation](https://cloud.google.com/spanner/docs/timestamp-bounds)
Inheritance
EventEmitter
>
Snapshot
Package
@google-cloud/spanner!
Constructors
(constructor)(session, options, queryOptions)
constructor(session: Session, options?: TimestampBounds, queryOptions?: IQueryOptions);
Constructs a new instance of the Snapshot
class
Parameters
Type | Name | Description |
---|
Session | session |
The parent Session object.
|
TimestampBounds | options |
Snapshot timestamp bounds.
|
google.spanner.v1.ExecuteSqlRequest.IQueryOptions | queryOptions |
Default query options to use when none are specified for a query.
|
Properties
_options
protected _options: spannerClient.spanner.v1.ITransactionOptions;
Property Value
Type | Description |
---|
ITransactionOptions | |
_seqno
protected _seqno: number;
Property Value
ended
Property Value
id
id?: Uint8Array | string;
Property Value
Type | Description |
---|
Uint8Array | string | |
metadata?: spannerClient.spanner.v1.ITransaction;
Property Value
Type | Description |
---|
ITransaction | |
queryOptions
queryOptions?: IQueryOptions;
Property Value
Type | Description |
---|
google.spanner.v1.ExecuteSqlRequest.IQueryOptions | |
readTimestamp
readTimestamp?: PreciseDate;
Property Value
Type | Description |
---|
PreciseDate | |
readTimestampProto
readTimestampProto?: spannerClient.protobuf.ITimestamp;
Property Value
Type | Description |
---|
ITimestamp | |
request
request: (config: {}, callback: Function) => void;
Property Value
Type | Description |
---|
(config: {}, callback: Function) => void | |
requestStream
requestStream: (config: {}) => Readable;
Property Value
Type | Description |
---|
(config: {}) => internal.Readable | |
resourceHeader_: {
[k: string]: string;
};
Property Value
Type | Description |
---|
{
[k: string]: string;
} | |
session
Property Value
Methods
begin(gaxOptions)
begin(gaxOptions?: CallOptions): Promise<BeginResponse>;
Parameter
Type | Name | Description |
---|
CallOptions | gaxOptions |
|
Returns
Type | Description |
---|
Promise<BeginResponse> | |
begin(callback)
begin(callback: BeginTransactionCallback): void;
Parameter
Type | Name | Description |
---|
BeginTransactionCallback | callback |
|
Returns
begin(gaxOptions, callback)
begin(gaxOptions: CallOptions, callback: BeginTransactionCallback): void;
Parameters
Type | Name | Description |
---|
CallOptions | gaxOptions |
|
BeginTransactionCallback | callback |
|
Returns
createReadStream(table, request)
createReadStream(table: string, request?: ReadRequest): PartialResultStream;
Create a readable object stream to receive rows from the database using key lookups and scans.
Wrapper around .
[StreamingRead API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.StreamingRead) [ReadRequest API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ReadRequest)
PartialResultStream#response PartialResultStream#stats
Parameters
Type | Name | Description |
---|
string | table |
The table to read from.
|
ReadRequest | request |
|
Returns
Type | Description |
---|
PartialResultStream | {ReadableStream} A readable stream that emits rows.
|
encodeKeySet(request)
static encodeKeySet(request: ReadRequest): spannerClient.spanner.v1.IKeySet;
Transforms convenience options keys
and ranges
into a KeySet object.
Parameter
Type | Name | Description |
---|
ReadRequest | request |
The read request.
|
Returns
Type | Description |
---|
IKeySet | {object}
|
encodeParams(request)
static encodeParams(request: ExecuteSqlRequest): {
params: p.IStruct;
paramTypes: {
[field: string]: spannerClient.spanner.v1.Type;
};
};
Encodes convenience options param
and types
into the proto formatted.
Parameter
Type | Name | Description |
---|
ExecuteSqlRequest | request |
The SQL request.
|
Returns
Type | Description |
---|
{
params: common.IStruct;
paramTypes: {
[field: string]: google.spanner.v1.Type;
};
} | {object}
|
encodeTimestampBounds(options)
static encodeTimestampBounds(options: TimestampBounds): spannerClient.spanner.v1.TransactionOptions.IReadOnly;
Formats timestamp options into proto format.
Parameter
Type | Name | Description |
---|
TimestampBounds | options |
The user supplied options.
|
Returns
Type | Description |
---|
IReadOnly | {object}
|
end()
Let the client know you're done with a particular transaction. This should mainly be called for Snapshot objects, however in certain cases you may want to call them for Transaction objects as well.
Returns
read(table, request)
read(table: string, request: ReadRequest): Promise<ReadResponse>;
Parameters
Type | Name | Description |
---|
string | table |
|
ReadRequest | request |
|
Returns
Type | Description |
---|
Promise<ReadResponse> | |
read(table, callback)
read(table: string, callback: ReadCallback): void;
Parameters
Type | Name | Description |
---|
string | table |
|
ReadCallback | callback |
|
Returns
read(table, request, callback)
read(table: string, request: ReadRequest, callback: ReadCallback): void;
Parameters
Type | Name | Description |
---|
string | table |
|
ReadRequest | request |
|
ReadCallback | callback |
|
Returns
run(query)
run(query: string | ExecuteSqlRequest): Promise<RunResponse>;
Parameter
Type | Name | Description |
---|
string | ExecuteSqlRequest | query |
|
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
runStream(query)
runStream(query: string | ExecuteSqlRequest): PartialResultStream;
Create a readable object stream to receive resulting rows from a SQL statement.
Wrapper around .
[ExecuteStreamingSql API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ExecuteStreamingSql) [ExecuteSqlRequest API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
PartialResultStream#response PartialResultStream#stats
Parameter
Type | Name | Description |
---|
string | ExecuteSqlRequest | query |
A SQL query or object.
|
Returns
Type | Description |
---|
PartialResultStream | {ReadableStream}
|