A TypeScript ORM for Google Cloud Spanner and PostgreSQL (including PGLite), inspired by Drizzle ORM. Current stable version is 0.2.2. It allows you to define a single schema using a composable, Drizzle-inspired syntax and then migrate or query both databases with dialect-aware SQL generation. Key differentiators include cross-dialect migrations, a fluent query builder, raw SQL fallback via template literals, and support for dynamic default values. It ships with TypeScript types and requires peer dependencies @google-cloud/spanner, pg, and @electric-sql/pglite depending on the target database. Development is at an early stage with frequent breaking changes likely.
npm install spanner-ormNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Defines a simple user schema with UUID primary key, timestamps, and queries for users using the query builder.
Pin to exact version and test upgrades thoroughly.
Use the current object-based syntax and monitor changelog for migration guides.
Run `npm install @google-cloud/spanner pg @electric-sql/pglite` as needed.
Use `$defaultFn` for dynamic defaults like `crypto.randomUUID()`.
Implement application-level cascading deletes for Spanner.
Install the package: `npm install spanner-orm@0.2.2`. Ensure your project uses ESM (type: module in package.json) or use a bundler.
Ensure you pass a valid database client (pg.Client or Spanner instance) to the query methods.
Use `new SpannerOrm({ dialect: 'postgres' })` or `{ dialect: 'spanner' }`.