@saplings/adapter-drizzle
v0.18.1
Published
Use PostgreSQL as the SDK store through Drizzle and node-postgres.
Readme
@saplings/adapter-drizzle
Use PostgreSQL as the SDK store through Drizzle and node-postgres.
Install
npm install @saplings/sdk @saplings/adapter-drizzle drizzle-orm pg
npm install --save-dev @types/pgQuick start
import { DrizzleStore } from '@saplings/adapter-drizzle';
import { createSapling } from '@saplings/sdk';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
const connectionString = process.env.DATABASE_URL;
if (!connectionString) throw new Error('Set DATABASE_URL');
const pool = new Pool({ connectionString });
const sdk = createSapling({
app: { id: 'my-app', environment: 'development' },
providers: { store: new DrizzleStore(drizzle(pool)) },
});
try {
console.log(await sdk.readiness());
} finally {
await pool.end();
}API and integration
- Apply the SQL files in this package's
migrations/in order with a migration role before starting the app. - Use a non-owner application role without
BYPASSRLS. Test cross-tenant reads and writes with the same role your service uses. DrizzleStoreimplements the SDKStoreinterface. Calltransaction(tenantId, work)for tenant-scoped operations that must commit together. Use the callback's transaction store insidework.
Read the integration guide for configuration and operational details.
