This directory contains a sample application demonstrating how to connect to Cloud Spanner through PGAdapter using the Drizzle ORM with the standard Node.js pg driver.
It demonstrates executing simple queries, batch DML, transactions, and Spanner-specific settings like stale reads.
- Node.js (version 24 or newer is recommended)
- Docker (required to run PGAdapter and the Spanner Emulator via Testcontainers)
To install the dependencies and execute the sample:
npm install
npm startThe sample application will:
- Automatically pull and start a Docker container running PGAdapter and the Spanner Emulator on a random port.
- Initialize connection configurations and define the database schema.
- Perform insert and query operations inside a transaction.
- Sell a ticket (inserting into
ticket_sales) to demonstrate auto-generating sequence-based primary keys. - Demonstrate a stale read by configuring
SET spanner.read_only_staleness. - Terminate the container once execution completes.