{"_id":"@deltic/async-pg-drizzle","_rev":"4-d2ba7157c5956b97882596906ca3e106","name":"@deltic/async-pg-drizzle","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.0":{"name":"@deltic/async-pg-drizzle","version":"0.1.0","keywords":["drizzle","pg","pool","async","postgres","orm"],"author":{"url":"https://frankdejonge.nl","name":"Frank de Jonge"},"license":"ISC","_id":"@deltic/async-pg-drizzle@0.1.0","maintainers":[{"name":"frankdejonge","email":"info@frankdejonge.nl"}],"homepage":"https://github.com/deltic-oss/deltic#readme","bugs":{"url":"https://github.com/deltic-oss/deltic/issues"},"dist":{"shasum":"c13f1d46bfc6997349a6c6e61438cb464f3b1749","tarball":"https://registry.npmjs.org/@deltic/async-pg-drizzle/-/async-pg-drizzle-0.1.0.tgz","fileCount":8,"integrity":"sha512-LVnz5m5KtJXI0aszxw23HpGfZRPlG1XmunY5vLRAJUjFvF9cnLC8qUX/xRueTkwuSYI0kOGSBvwrXFn/JNbxrg==","signatures":[{"sig":"MEUCIGgoaSDOtHNS0PUg30KbSA7WZUmc4G6vMZ/0Bg2EKjdvAiEAiuTd1RhDV/So2Xd3k7lcjCt3+PCLNAIf8t9W/6yi/NA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":41590},"type":"module","_from":"file:deltic-async-pg-drizzle-0.1.0.tgz","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs","module-sync":"./dist/index.js"}},"scripts":{},"_npmUser":{"name":"frankdejonge","email":"info@frankdejonge.nl"},"_resolved":"/private/var/folders/cf/f1s7n7kd3938zynwcqk8_2z00000gn/T/67441691b8e871430594e7195b369f15/deltic-async-pg-drizzle-0.1.0.tgz","_integrity":"sha512-LVnz5m5KtJXI0aszxw23HpGfZRPlG1XmunY5vLRAJUjFvF9cnLC8qUX/xRueTkwuSYI0kOGSBvwrXFn/JNbxrg==","repository":{"url":"git+https://github.com/deltic-oss/deltic.git","type":"git","directory":"packages/async-pg-drizzle"},"_npmVersion":"11.6.0","description":"Drizzle ORM integration with @deltic/async-pg-pool","directories":{},"_nodeVersion":"24.8.0","dependencies":{"drizzle-orm":"^0.45.0","@deltic/async-pg-pool":"^0.2.0","@deltic/error-standard":"^0.1.1"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.16.3","@types/pg":"^8.15.6"},"peerDependencies":{"pg":"^8.16.3","@deltic/async-pg-pool":"^0.2.0"},"_npmOperationalInternal":{"tmp":"tmp/async-pg-drizzle_0.1.0_1774450016260_0.3206705176057838","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@deltic/async-pg-drizzle","version":"0.1.1","keywords":["drizzle","pg","pool","async","postgres","orm"],"author":{"url":"https://frankdejonge.nl","name":"Frank de Jonge"},"license":"ISC","_id":"@deltic/async-pg-drizzle@0.1.1","maintainers":[{"name":"frankdejonge","email":"info@frankdejonge.nl"}],"homepage":"https://github.com/deltic-oss/deltic#readme","bugs":{"url":"https://github.com/deltic-oss/deltic/issues"},"dist":{"shasum":"29b57a6d057f984e93cbb57ec47cd4620ea0ac35","tarball":"https://registry.npmjs.org/@deltic/async-pg-drizzle/-/async-pg-drizzle-0.1.1.tgz","fileCount":8,"integrity":"sha512-EViv6OxbzUNY2JKtJ7qwTXY3ljkeGyQdwigFPHLrExDMd2gyMkJYCHGjsWkRsDsVkyjSL1j1oLqlWPaIDsoFUw==","signatures":[{"sig":"MEUCIHQbJZdF2baJyf/0kPWhko0qYdNTHMj0zKkAM3WjxFmvAiEA2wB+9FSyHORyIev3ec2FtUnOFY3HJdwrBgpT6gDcA/Y=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":41771},"type":"module","_from":"file:deltic-async-pg-drizzle-0.1.1.tgz","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs","module-sync":"./dist/index.mjs"}},"scripts":{},"_npmUser":{"name":"frankdejonge","email":"info@frankdejonge.nl"},"_resolved":"/private/var/folders/cf/f1s7n7kd3938zynwcqk8_2z00000gn/T/c93e9046115daf59550585cf61e78cd5/deltic-async-pg-drizzle-0.1.1.tgz","_integrity":"sha512-EViv6OxbzUNY2JKtJ7qwTXY3ljkeGyQdwigFPHLrExDMd2gyMkJYCHGjsWkRsDsVkyjSL1j1oLqlWPaIDsoFUw==","repository":{"url":"git+https://github.com/deltic-oss/deltic.git","type":"git","directory":"packages/async-pg-drizzle"},"_npmVersion":"11.6.0","description":"Drizzle ORM integration with @deltic/async-pg-pool","directories":{},"_nodeVersion":"24.8.0","dependencies":{"drizzle-orm":"^0.45.0","@deltic/async-pg-pool":"^0.2.1","@deltic/error-standard":"^0.1.2"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.16.3","@types/pg":"^8.15.6"},"peerDependencies":{"pg":"^8.16.3","@deltic/async-pg-pool":"^0.2.1"},"_npmOperationalInternal":{"tmp":"tmp/async-pg-drizzle_0.1.1_1774454217217_0.4695352294147468","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@deltic/async-pg-drizzle","version":"0.1.2","keywords":["drizzle","pg","pool","async","postgres","orm"],"author":{"url":"https://frankdejonge.nl","name":"Frank de Jonge"},"license":"ISC","_id":"@deltic/async-pg-drizzle@0.1.2","maintainers":[{"name":"frankdejonge","email":"info@frankdejonge.nl"}],"homepage":"https://github.com/deltic-oss/deltic#readme","bugs":{"url":"https://github.com/deltic-oss/deltic/issues"},"dist":{"shasum":"459f8ae76ee268272c534f93fbfdf4fd7ad16ff6","tarball":"https://registry.npmjs.org/@deltic/async-pg-drizzle/-/async-pg-drizzle-0.1.2.tgz","fileCount":8,"integrity":"sha512-zNf0pyQDEXQlS8Bu6q2bajhC6udRsn+/peToninjXJpJyP2RcAMZdgNFkPJTKVOCLHE5A0b6ceL/d5krrLj+vw==","signatures":[{"sig":"MEQCIDb3XdZ68f4DHq41nhXLwc07l65oxJIEluRZ8BreJ0S8AiABjSmA+vUoe/Sv3dEAftTsBlHr66r3nlYtF5e0cC4q+w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":41951},"type":"module","_from":"file:deltic-async-pg-drizzle-0.1.2.tgz","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs","require":"./dist/index.cjs","module-sync":"./dist/index.mjs"}},"scripts":{},"_npmUser":{"name":"frankdejonge","email":"info@frankdejonge.nl"},"_resolved":"/private/var/folders/cf/f1s7n7kd3938zynwcqk8_2z00000gn/T/6b4ae531ba57d59e62f4054cb31528b2/deltic-async-pg-drizzle-0.1.2.tgz","_integrity":"sha512-zNf0pyQDEXQlS8Bu6q2bajhC6udRsn+/peToninjXJpJyP2RcAMZdgNFkPJTKVOCLHE5A0b6ceL/d5krrLj+vw==","repository":{"url":"git+https://github.com/deltic-oss/deltic.git","type":"git","directory":"packages/async-pg-drizzle"},"_npmVersion":"11.6.0","description":"Drizzle ORM integration with @deltic/async-pg-pool","directories":{},"_nodeVersion":"24.8.0","dependencies":{"drizzle-orm":"^0.45.0","@deltic/async-pg-pool":"^0.2.2","@deltic/error-standard":"^0.1.3"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.16.3","@types/pg":"^8.15.6"},"peerDependencies":{"pg":"^8.16.3","@deltic/async-pg-pool":"^0.2.2"},"_npmOperationalInternal":{"tmp":"tmp/async-pg-drizzle_0.1.2_1774454584593_0.4430079963486433","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@deltic/async-pg-drizzle","type":"module","version":"0.1.3","description":"Drizzle ORM integration with @deltic/async-pg-pool","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","module-sync":"./dist/index.mjs","types":"./dist/index.d.mts"}},"keywords":["drizzle","pg","pool","async","postgres","orm"],"author":{"name":"Frank de Jonge","url":"https://frankdejonge.nl"},"license":"ISC","dependencies":{"drizzle-orm":"^0.45.2","@deltic/async-pg-pool":"^0.2.4","@deltic/error-standard":"^0.1.3"},"peerDependencies":{"pg":"^8.16.3","@deltic/async-pg-pool":"^0.2.4"},"devDependencies":{"@types/pg":"^8.20.0","pg":"^8.20.0"},"repository":{"type":"git","url":"git+https://github.com/deltic-oss/deltic.git","directory":"packages/async-pg-drizzle"},"scripts":{},"_id":"@deltic/async-pg-drizzle@0.1.3","bugs":{"url":"https://github.com/deltic-oss/deltic/issues"},"homepage":"https://github.com/deltic-oss/deltic#readme","_integrity":"sha512-NbTQwPKPdzAM9w1mrBJb1xYW0EzniUdFNqZpa/MZMH3I+SExLj0oxrNjhA0ar8cX4o/S5vzjj8codIu5oTIM+Q==","_resolved":"/private/var/folders/cf/f1s7n7kd3938zynwcqk8_2z00000gn/T/025f1678cd048064e2b4cb37dd195e7d/deltic-async-pg-drizzle-0.1.3.tgz","_from":"file:deltic-async-pg-drizzle-0.1.3.tgz","_nodeVersion":"24.8.0","_npmVersion":"11.6.0","dist":{"integrity":"sha512-NbTQwPKPdzAM9w1mrBJb1xYW0EzniUdFNqZpa/MZMH3I+SExLj0oxrNjhA0ar8cX4o/S5vzjj8codIu5oTIM+Q==","shasum":"6e7f8c403bd30073dc52502ac0bc0248752a6a62","tarball":"https://registry.npmjs.org/@deltic/async-pg-drizzle/-/async-pg-drizzle-0.1.3.tgz","fileCount":8,"unpackedSize":44123,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDm85ZZgqgwBNO2liPKPrHuieYJ7a1JB2pYxHD4m55ZWwIgIRtE7ZXebBRav2gCASd/UrMZMLIgv0elgWSb8GuqBPY="}]},"_npmUser":{"name":"frankdejonge","email":"info@frankdejonge.nl"},"directories":{},"maintainers":[{"name":"frankdejonge","email":"info@frankdejonge.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/async-pg-drizzle_0.1.3_1777881499323_0.9361066157164457"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-25T14:46:56.159Z","modified":"2026-05-04T07:58:19.588Z","0.1.0":"2026-03-25T14:46:56.402Z","0.1.1":"2026-03-25T15:56:57.388Z","0.1.2":"2026-03-25T16:03:04.752Z","0.1.3":"2026-05-04T07:58:19.460Z"},"bugs":{"url":"https://github.com/deltic-oss/deltic/issues"},"author":{"name":"Frank de Jonge","url":"https://frankdejonge.nl"},"license":"ISC","homepage":"https://github.com/deltic-oss/deltic#readme","keywords":["drizzle","pg","pool","async","postgres","orm"],"repository":{"type":"git","url":"git+https://github.com/deltic-oss/deltic.git","directory":"packages/async-pg-drizzle"},"description":"Drizzle ORM integration with @deltic/async-pg-pool","maintainers":[{"name":"frankdejonge","email":"info@frankdejonge.nl"}],"readme":"# @deltic/async-pg-drizzle\n\nDrizzle ORM integration with `@deltic/async-pg-pool`, giving you full control over connection and transaction management while keeping Drizzle's type-safe query building API.\n\n## Why?\n\nDrizzle ORM manages connections and transactions internally. When you call `db.transaction()`, Drizzle checks out a connection, issues `BEGIN`, runs your callback, and commits or rolls back. This works for simple applications, but you lose control over important aspects:\n\n- **Shared transactions** - Multiple independent modules (event store, projections, outbox) can't participate in the same transaction without passing a `tx` object around\n- **Connection lifecycle hooks** - No way to run setup/teardown queries on connections (e.g., setting `app.tenant_id` for row-level security)\n- **Request-scoped connections** - No built-in way to reuse a connection across an HTTP request\n- **Cross-ORM transactions** - Can't share a transaction between Drizzle and Knex queries\n\n`@deltic/async-pg-drizzle` bridges Drizzle's query builder with `@deltic/async-pg-pool`. You get Drizzle's full type-safe API while `AsyncPgPool` handles all connection and transaction management:\n\n```typescript\nconst db = new AsyncDrizzleConnectionProvider(asyncPool, {schema});\n\n// Queries — connections managed by AsyncPgPool\nconst users = await db.connection().select().from(usersTable);\n\n// Transactions — managed by the provider, not by Drizzle\nawait db.runInTransaction(async () => {\n    await db.connection().insert(usersTable).values({name: 'Frank'});\n    await db.connection().insert(auditTable).values({action: 'user_created'});\n});\n```\n\n## Installation\n\n```bash\nnpm install @deltic/async-pg-drizzle @deltic/async-pg-pool drizzle-orm pg\n```\n\n## Quick Start\n\n```typescript\nimport {Pool} from 'pg';\nimport {AsyncPgPool} from '@deltic/async-pg-pool';\nimport {AsyncDrizzleConnectionProvider} from '@deltic/async-pg-drizzle';\nimport * as schema from './schema';\n\n// Create the connection stack\nconst pgPool = new Pool({connectionString: 'postgresql://...'});\nconst asyncPool = new AsyncPgPool(pgPool);\nconst db = new AsyncDrizzleConnectionProvider(asyncPool, {schema});\n\n// Query with lazy connection resolution\nconst users = await db.connection()\n    .select()\n    .from(schema.usersTable)\n    .where(eq(schema.usersTable.active, true));\n```\n\n## Usage\n\n### Basic Queries\n\n```typescript\n// SELECT\nconst users = await db.connection()\n    .select()\n    .from(usersTable)\n    .where(eq(usersTable.active, true));\n\n// SELECT specific columns\nconst names = await db.connection()\n    .select({name: usersTable.name, email: usersTable.email})\n    .from(usersTable);\n\n// INSERT with returning\nconst [newUser] = await db.connection()\n    .insert(usersTable)\n    .values({name: 'Alice', email: 'alice@example.com'})\n    .returning();\n\n// UPDATE\nawait db.connection()\n    .update(usersTable)\n    .set({lastLogin: new Date()})\n    .where(eq(usersTable.id, userId));\n\n// DELETE\nawait db.connection()\n    .delete(usersTable)\n    .where(eq(usersTable.id, userId));\n```\n\n### Raw SQL\n\n```typescript\nconst result = await db.connection().execute(\n    sql`SELECT * FROM users WHERE age > ${21}`,\n);\n```\n\n### Transactions\n\nTransactions acquire a dedicated connection for their duration:\n\n```typescript\nconst trx = await db.begin();\n\ntry {\n    await trx\n        .update(accountsTable)\n        .set({balance: sql`balance - ${amount}`})\n        .where(eq(accountsTable.id, fromAccountId));\n\n    await trx\n        .update(accountsTable)\n        .set({balance: sql`balance + ${amount}`})\n        .where(eq(accountsTable.id, toAccountId));\n\n    await trx.insert(transfersTable).values({\n        fromAccount: fromAccountId,\n        toAccount: toAccountId,\n        amount,\n    });\n\n    await db.commit(trx);\n} catch (error) {\n    await db.rollback(trx);\n    throw error;\n}\n```\n\n#### Using `runInTransaction`\n\nFor simpler transaction handling with automatic commit/rollback:\n\n```typescript\nconst user = await db.runInTransaction(async () => {\n    const [user] = await db.connection()\n        .insert(usersTable)\n        .values({name: 'Bob'})\n        .returning();\n\n    await db.connection()\n        .insert(auditLogTable)\n        .values({action: 'user_created', userId: user.id});\n\n    return user;\n});\n```\n\nIf the function throws, the transaction is automatically rolled back. Nested calls to `runInTransaction` reuse the existing transaction.\n\n#### Custom Isolation Levels\n\n```typescript\nconst trx = await db.begin('BEGIN ISOLATION LEVEL SERIALIZABLE');\n// ... your queries\nawait db.commit(trx);\n```\n\n### Using `connection()` Inside Transactions\n\nThe `connection()` method is transaction-aware. When a transaction is active, queries executed through `connection()` automatically use the transaction connection:\n\n```typescript\nawait db.runInTransaction(async () => {\n    // Both queries run on the same transaction connection\n    await db.connection().insert(usersTable).values({name: 'Frank'});\n    await db.connection().insert(auditTable).values({action: 'user_created'});\n});\n```\n\nThis means modules that use `db.connection()` internally don't need to know whether they're running inside a transaction or not.\n\n### Side-by-Side with Knex\n\nBecause both `@deltic/async-pg-drizzle` and `@deltic/async-pg-knex` delegate connection management to the same `AsyncPgPool`, they can share transactions:\n\n```typescript\nconst drizzleDb = new AsyncDrizzleConnectionProvider(asyncPool, {schema});\nconst knexDb = new AsyncKnexConnectionProvider(asyncPool);\n\nawait asyncPool.runInTransaction(async () => {\n    // Drizzle query — uses the shared transaction connection\n    await drizzleDb.connection()\n        .insert(usersTable)\n        .values({name: 'Frank'});\n\n    // Knex query — same transaction, same connection\n    await knexDb.connection()('audit_log')\n        .insert({action: 'user_created'});\n});\n```\n\n## API Reference\n\n### `AsyncDrizzleConnectionProvider`\n\n#### Constructor\n\n```typescript\nnew AsyncDrizzleConnectionProvider(pool: AsyncPgPool, options?: {\n    schema?: TSchema;\n    logger?: boolean | Logger;\n    casing?: 'snake_case' | 'camelCase';\n})\n```\n\nThe `schema` option enables Drizzle's typed relational queries. The `logger` and `casing` options are passed through to Drizzle's configuration.\n\n#### Methods\n\n| Method | Description |\n|--------|-------------|\n| `connection()` | Returns a `NodePgDatabase` instance for building queries |\n| `begin(query?)` | Begins a transaction, returns a `NodePgDatabase` bound to it |\n| `commit(trx)` | Commits a transaction |\n| `rollback(trx, error?)` | Rolls back a transaction |\n| `withTransaction()` | Returns the current transaction instance (throws if none) |\n| `inTransaction()` | Returns `true` if currently in a transaction |\n| `runInTransaction(fn)` | Runs a function in a transaction with auto commit/rollback |\n\n### Drizzle's `db.transaction()` Is Blocked\n\nAll `NodePgDatabase` instances created by this provider have Drizzle's built-in `db.transaction()` overridden to throw `DrizzleTransactionsNotSupported`. This prevents accidentally using Drizzle's internal transaction management, which would issue `BEGIN`/`COMMIT`/`ROLLBACK` on the pool-managed connection and corrupt the transaction state.\n\nUse the provider's `begin()`/`commit()`/`rollback()` or `runInTransaction()` instead.\n\n## How It Works\n\nUnder the hood, the provider creates a lightweight wrapper object with a single `query()` method. This object is passed to Drizzle as if it were a pg client. Drizzle only calls `client.query()` during normal operations, so the wrapper intercepts every query and routes it through `AsyncPgPool`:\n\n1. **`connection()`** returns a Drizzle instance backed by the lazy wrapper\n2. **When a query executes**, the wrapper calls `pool.primary()` to get the current connection (respecting transaction context)\n3. **The query runs** on the resolved connection via `connection.query()`\n4. **The connection is released** back to the pool (unless in a transaction)\n\n**Transactions** work differently: `begin()` creates a new Drizzle instance bound directly to the transaction's pg connection. All queries on that instance execute on the dedicated transaction connection until commit or rollback.\n\n### Integration with AsyncPgPool Features\n\nBecause connections flow through `AsyncPgPool`, you get all its features:\n\n```typescript\nconst asyncPool = new AsyncPgPool(pgPool, {\n    // Run on every connection claim\n    onClaim: client => client.query(`SET app.tenant_id = '${tenantId}'`),\n    // Run on every connection release\n    onRelease: 'RESET app.tenant_id',\n    // Keep connections warm\n    keepConnections: 2,\n    maxIdleMs: 5000,\n});\n\nconst db = new AsyncDrizzleConnectionProvider(asyncPool, {schema});\n\n// Queries automatically get tenant_id set\nconst users = await db.connection().select().from(usersTable);\n```\n\n## License\n\nISC\n","readmeFilename":"README.md"}