> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Cloud Spanner

> Read a table at an exact timestamp or capture a Spanner change stream.

## Table at a read timestamp

Create a Spanner session on the selected database using the reading principal.
Mount [`@bijectionhq/app-rest`](https://docs.bijection.com/integrations/native-rest#mount-and-bind) once
per table and read timestamp. Pass as `receivers.provider` a receiver bound to the session's resource
name with the `:executeSql` suffix.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export const remote = providerEndpoint(
  "spanner.table.read-timestamp", "https://spanner.googleapis.com",
  "/v1/projects/my-project/instances/inventory/databases/stock/sessions/SESSION_ID:executeSql",
  { kind: "bearer", secret: accessToken }, data,
);
```

Seal a Google access token with `spanner.data` or `cloud-platform` OAuth
scope and access to the table. The installer owns the session and its cleanup.
Bind the receiver and the mount under the same `data` label.
Select a UTC timestamp within the database's version-retention interval.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{ profile: { mode: "provider", provider: "spanner.table.read-timestamp",
  collection: "Items", selection: "Id", fields: ["Name"], start: "2026-11-24T09:00:00.123456789Z", limit: 16 } }
```

Use one unique, non-null INT64 key and up to fifteen projected columns. The
read-only query binds the exact timestamp and the exclusive decimal key
boundary on every page. Rows land as Spanner JSON, with up to 32 rows and
36 KiB per page. A short page completes the finite read. Missing keys
remain. An expired session or unavailable read timestamp stops advance.

[Spanner ExecuteSql API](https://docs.cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases.sessions/executeSql)

## Change streams

Enable a change stream and create a reading session on its database.
Mount `@bijectionhq/app-documents` with the `data` label.
Follow the [Google stream mount example](https://docs.bijection.com/integrations/native-bigtable#mount-a-google-stream),
use `spannerStream(credential, data)` from that package,
and pass it as `provider`. The receiver and the mount use the
same label. Grant the principal access to query the
change stream using the `spanner.data` or `cloud-platform` scope. The installer
owns session creation and cleanup.

Seal the following JSON in the receiver credential.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "accessToken": "GOOGLE_ACCESS_TOKEN",
  "scope": {
    "provider": "spanner",
    "session": "projects/my-project/instances/inventory/databases/stock/sessions/SESSION_ID",
    "stream": "ItemsChanges",
    "dialect": "googleSql"
  }
}
```

Initialize with that session, stream, and dialect, and a UTC timestamp
within the stream's retention interval. Use `postgreSql` for the PostgreSQL
dialect.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  selection: { mode: "spanner.change-stream", terms: {
    session: "projects/my-project/instances/inventory/databases/stock/sessions/SESSION_ID",
    stream: "ItemsChanges",
    dialect: "googleSql",
    start: "2026-11-24T09:00:00Z",
  } },
}
```

The receiver assembles partial result values and reads one partition per
pass. The app records the heartbeat watermark and inherits each child
partition's reported start time. A child becomes eligible after all its
parents reach successful stream completion and publish its lineage.
Independent partitions rotate through bounded turns.

Each partition resumes inclusively at its last published timestamp.
The app retains up to 32 event identities at that boundary until the stream
advances or a heartbeat proves the timestamp covered. This lets one session
read multiple partitions without sharing RPC resume tokens. The projection
keys each change by a digest of the commit timestamp, transaction ID and
record sequence. It stores GoogleSQL records as positional Spanner values
and PostgreSQL records as provider JSON text. Deletes remain change records.
A transaction spanning partitions may land in multiple commits.

A pass is limited to 20 seconds, 32 events and 48 KiB of answer data within
the action result's encoded bound. The app permits up to 64 child announcements
in a closing pass, 16 parents per child and 1,024 partition announcements per
generation. An oversized page, expired session or rejected position holds
the checkpoint. Inspect `source.health` and `source.partitions` before
resetting. Use a new mount when changing the sealed session or start contract.

[Spanner change stream queries and lineage](https://docs.cloud.google.com/spanner/docs/change-streams/details)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.