{"_id":"@aopslabs/xf-db-drizzle","_rev":"3-22d0d03bde2a2b9852db420c7b1c2585","name":"@aopslabs/xf-db-drizzle","dist-tags":{"latest":"0.2.2"},"versions":{"0.2.0":{"name":"@aopslabs/xf-db-drizzle","version":"0.2.0","license":"SEE LICENSE IN LICENSE","_id":"@aopslabs/xf-db-drizzle@0.2.0","maintainers":[{"name":"mzsonmez","email":"mzsonmez2@hotmail.com"}],"homepage":"https://github.com/eeemzs/xf-packages#readme","bugs":{"url":"https://github.com/eeemzs/xf-packages/issues"},"dist":{"shasum":"80bcc4b8aa47027e5e967f92ec1346327a4fe8ef","tarball":"https://registry.npmjs.org/@aopslabs/xf-db-drizzle/-/xf-db-drizzle-0.2.0.tgz","fileCount":32,"integrity":"sha512-vyInKwQ+uEbvghHBZsLvKnHPZlYch9Sl2U5wVn5MNktcfH2WQd+hlSXtoIKzCm0pB72cYWOnpYuT7y0FrdRtng==","signatures":[{"sig":"MEQCIHSGzOBp3M4MWx6pkkEI+X9dX8QTmP/1w9eRp9tclvt7AiAD/DJCwgyhzzc0dwAvJTlMOiTgy5wmgHMijHqK6Ge1yw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":101161},"main":"./dist/index.js","type":"module","_from":"file:S:/dev-js2/tmp/xf-public-b3-efd8c9b-r2/aopslabs-xf-db-drizzle-0.2.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"private":false,"scripts":{"build":"tsc -p tsconfig.lib.json"},"_npmUser":{"name":"mzsonmez","email":"mzsonmez2@hotmail.com"},"_resolved":"S:\\dev-js2\\tmp\\xf-public-b3-efd8c9b-r2\\aopslabs-xf-db-drizzle-0.2.0.tgz","_integrity":"sha512-vyInKwQ+uEbvghHBZsLvKnHPZlYch9Sl2U5wVn5MNktcfH2WQd+hlSXtoIKzCm0pB72cYWOnpYuT7y0FrdRtng==","repository":{"url":"git+https://github.com/eeemzs/xf-packages.git","type":"git"},"_npmVersion":"11.6.4","description":"Drizzle ORM repository and transaction adapters for PostgreSQL and SQLite TypeScript applications.","directories":{},"_nodeVersion":"22.18.0","dependencies":{"pg":"8.20.0","tslib":"^2.3.0","effect":"3.20.0","@aopslabs/xf-bm":"^0.2.0","@aopslabs/xf-db":"^0.2.0","@aopslabs/xf-core":"^0.2.0","@aopslabs/xf-logger":"^0.2.1"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"@types/pg":"8.20.0","typescript":"^5.9.3","@types/node":"^25.3.0","drizzle-orm":"^0.45.2","@opentelemetry/api":"1.9.1"},"peerDependencies":{"drizzle-orm":"^0.45.2"},"optionalDependencies":{"better-sqlite3":"12.10.0"},"_npmOperationalInternal":{"tmp":"tmp/xf-db-drizzle_0.2.0_1785860487141_0.2294732656339571","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@aopslabs/xf-db-drizzle","version":"0.2.1","license":"SEE LICENSE IN LICENSE","_id":"@aopslabs/xf-db-drizzle@0.2.1","maintainers":[{"name":"mzsonmez","email":"mzsonmez2@hotmail.com"}],"homepage":"https://github.com/eeemzs/tsapps#readme","bugs":{"url":"https://github.com/eeemzs/tsapps/issues"},"dist":{"shasum":"0a10b2235c28b439fdad2e1c0612e6adcc960bff","tarball":"https://registry.npmjs.org/@aopslabs/xf-db-drizzle/-/xf-db-drizzle-0.2.1.tgz","fileCount":34,"integrity":"sha512-ci+kc6mosrgbyMRrNQ9blRPNjzPD9S0l92vrsx2yjTJ7JZizV74CNDkIepfrAeoo7cgtYERp1ys10JTWWQx2/g==","signatures":[{"sig":"MEQCIDdNqmQzLritiaRCt8LH2masopBRliOABrcAsjlevZWsAiAbdNEXNf2tWgrOrDfBwV40ErMPJn2rtGi5zIT3PfR21g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":113731},"main":"./dist/index.js","type":"module","_from":"file:/home/runner/work/_temp/release-candidates/aopslabs-xf-db-drizzle-0.2.1.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"private":false,"scripts":{"lint":"eslint . --max-warnings=0","build":"tsc -p tsconfig.lib.json","test:sqlite":"node --test --test-timeout=10000 test/sqlite-*.test.mjs"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9f65c154-0188-498a-a8b4-efa8f3e21b48"}},"_resolved":"/home/runner/work/_temp/release-candidates/aopslabs-xf-db-drizzle-0.2.1.tgz","_integrity":"sha512-ci+kc6mosrgbyMRrNQ9blRPNjzPD9S0l92vrsx2yjTJ7JZizV74CNDkIepfrAeoo7cgtYERp1ys10JTWWQx2/g==","repository":{"url":"git+https://github.com/eeemzs/tsapps.git","type":"git","directory":"packages/xf-packages/xf-db-drizzle"},"_npmVersion":"11.9.0","description":"Drizzle ORM repository and transaction adapters for PostgreSQL and SQLite TypeScript applications.","directories":{},"_nodeVersion":"24.20.0","dependencies":{"pg":"8.20.0","tslib":"^2.3.0","effect":"3.20.0","@aopslabs/xf-bm":"^0.2.1","@aopslabs/xf-db":"^0.2.1","@aopslabs/xf-core":"^0.2.1","@aopslabs/xf-logger":"^0.2.2"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"9.39.5","@types/pg":"8.20.0","typescript":"5.9.3","@types/node":"25.3.0","drizzle-orm":"0.45.2","@opentelemetry/api":"1.9.1","@aopslabs/eslint-config":"0.0.0","@aopslabs/typescript-config":"0.0.0"},"peerDependencies":{"drizzle-orm":"0.45.2"},"optionalDependencies":{"better-sqlite3":"12.10.0"},"_npmOperationalInternal":{"tmp":"tmp/xf-db-drizzle_0.2.1_1788791315169_0.8178797716595874","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"_id":"@aopslabs/xf-db-drizzle@0.2.2","bugs":{"url":"https://github.com/eeemzs/tsapps/issues"},"dist":{"shasum":"b0736d958ac692c5cfbd7d1bda0dd70d5046a078","tarball":"https://registry.npmjs.org/@aopslabs/xf-db-drizzle/-/xf-db-drizzle-0.2.2.tgz","fileCount":38,"integrity":"sha512-56KmTHBBBu+7Si2fYi5WhDLt/qvJ+RePQZ5jWfdYV4r6GOqkB/XZAwK97ZJjsz+fNDV0LGEv/rcmiIIqBqqpBA==","signatures":[{"sig":"MEYCIQDtNSs0eZmZpRH8OdyWakyqyM4mmJresr6V1swYmOi2NwIhAMavCKLCOuJJtf4OGjp1txPgDzXZ2vsXgbRpzAdAZkXc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDGgccZ7qHlj3ax44HdyS0dkEUMo8tdZYqTb5QJzQ2uOQIgRtcq0v/i2Ye6EJcz8yNhIymCuRpOxJWdsZe30zpK/tA="}],"unpackedSize":142101},"main":"./dist/index.js","name":"@aopslabs/xf-db-drizzle","type":"module","_from":"file:/home/runner/work/_temp/release-candidates/aopslabs-xf-db-drizzle-0.2.2.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"},"./package.json":"./package.json"},"license":"SEE LICENSE IN LICENSE","private":false,"scripts":{"lint":"eslint . --max-warnings=0","build":"tsc -p tsconfig.lib.json","test:pg":"node --test --test-timeout=15000 test/pg-resource.test.mjs","test:sqlite":"node --test --test-timeout=10000 test/sqlite-*.test.mjs","test:pg:compat":"node --test --test-timeout=15000 test/pg-compatibility.test.mjs","test:pg:repository":"node --test --test-timeout=15000 test/pg-repository.test.mjs"},"version":"0.2.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9f65c154-0188-498a-a8b4-efa8f3e21b48"}},"homepage":"https://github.com/eeemzs/tsapps#readme","_resolved":"/home/runner/work/_temp/release-candidates/aopslabs-xf-db-drizzle-0.2.2.tgz","_integrity":"sha512-56KmTHBBBu+7Si2fYi5WhDLt/qvJ+RePQZ5jWfdYV4r6GOqkB/XZAwK97ZJjsz+fNDV0LGEv/rcmiIIqBqqpBA==","repository":{"url":"git+https://github.com/eeemzs/tsapps.git","type":"git","directory":"packages/xf-packages/xf-db-drizzle"},"_npmVersion":"11.9.0","description":"Drizzle ORM repository and transaction adapters for PostgreSQL and SQLite TypeScript applications.","directories":{},"maintainers":[{"name":"mzsonmez","email":"mzsonmez2@hotmail.com"}],"_nodeVersion":"24.20.0","dependencies":{"pg":"8.20.0","tslib":"^2.3.0","effect":"3.20.0","@aopslabs/xf-bm":"^0.2.1","@aopslabs/xf-db":"^0.2.2","@aopslabs/xf-core":"^0.2.1","@aopslabs/xf-logger":"^0.2.2"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"9.39.5","@types/pg":"8.20.0","typescript":"5.9.3","@types/node":"25.3.0","drizzle-orm":"0.45.2","@opentelemetry/api":"1.9.1","@aopslabs/eslint-config":"0.0.0","@aopslabs/typescript-config":"0.0.0"},"peerDependencies":{"drizzle-orm":"0.45.2"},"optionalDependencies":{"better-sqlite3":"12.10.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/xf-db-drizzle_0.2.2_1789257868410_0.24875581409610903"}}},"time":{"created":"2026-08-04T16:21:26.898Z","modified":"2026-09-13T00:04:28.682Z","0.2.0":"2026-08-04T16:21:27.322Z","0.2.1":"2026-09-07T14:28:35.310Z","0.2.2":"2026-09-13T00:04:28.526Z"},"bugs":{"url":"https://github.com/eeemzs/tsapps/issues"},"license":"SEE LICENSE IN LICENSE","homepage":"https://github.com/eeemzs/tsapps#readme","repository":{"url":"git+https://github.com/eeemzs/tsapps.git","type":"git","directory":"packages/xf-packages/xf-db-drizzle"},"description":"Drizzle ORM repository and transaction adapters for PostgreSQL and SQLite TypeScript applications.","maintainers":[{"name":"mzsonmez","email":"mzsonmez2@hotmail.com"}],"readme":"# @aopslabs/xf-db-drizzle\n\nDrizzle ORM repository and transaction adapters for PostgreSQL and SQLite TypeScript applications.\n\n## Install\n\n```bash\nnpm install @aopslabs/xf-db-drizzle drizzle-orm\n```\n\nInstall `better-sqlite3` as well when using the local SQLite driver.\n\n## Usage\n\n```ts\nimport { drizzleConnect, DraBase, DrizzleUnitOfWork } from '@aopslabs/xf-db-drizzle';\n\nawait drizzleConnect({ uri: process.env.DATABASE_URL });\n```\n\nThe package includes connection helpers, base repositories, query utilities, and unit-of-work implementations for PostgreSQL and SQLite.\n\n## Hosted PostgreSQL resources\n\nThe application owns database connections. A domain captures a lease during its\nfactory/bootstrap call and retains it for later operations:\n\n```ts\nimport { drizzle } from 'drizzle-orm/node-postgres';\nimport {\n  createPgOwner, configurePgBinding, withPgOwner, capturePgLease, closePgOwner,\n} from '@aopslabs/xf-db-drizzle';\n\nconst owner = createPgOwner();\nconfigurePgBinding(owner, 'main', {\n  uri: process.env.DATABASE_URL!,\n  poolOptions: { max: 10, application_name: 'example' },\n});\n\nconst plugin = withPgOwner(owner, () => {\n  const lease = capturePgLease('main');\n  return {\n    run: () => lease.run(async pool => {\n      const db = drizzle({ client: pool }); // This consumer owns its ORM wrapper.\n      return db.execute('select 1');\n    }),\n    dispose: () => lease.release(),\n  };\n});\n\nawait plugin.run();\nawait plugin.dispose();\nawait closePgOwner(owner);\n```\n\nConfiguration is lazy: declaring a binding opens no connection. Owner tokens and\nlogical binding names identify resources; connection strings are never registry\nkeys. Distinct names own distinct pools, even for the same database. An app may\nexplicitly share one resource with `aliasPgBinding(owner, 'other', 'main')`.\n`acquirePgLease(owner, name)` also supports explicit factory injection without the\nbootstrap bridge. Do not look up an ambient owner in a request handler.\nClose the owner before dropping its last reference; garbage collection does not\nclose network connections.\n\nWrap the **whole operation**, including query gaps and transactions, in\n`lease.run`. Returning a database/client for use after the callback, or starting\nunawaited work, escapes that lifetime. Releasing a plugin rejects its new work and\ndrains its existing work without closing siblings. The host must first stop new\noperations and workers, then dispose plugins, then close its owner. Each close\nwait defaults to 30 seconds; `{ timeoutMs }` changes that caller's wait only. A\ntimeout retains the closing resource and a later call observes the same cleanup.\nA rejected `Pool.end` is retained as `PG_CLOSE_FAILED`; the owner cannot be\nreopened and the pool is never ended twice.\n\nUse `runPgEphemeral(owner, options, work)` for an operation that requires its own\ntemporary pool capacity (for example, a nonblocking advisory-lock guard). Its\ncallback and cleanup participate in owner drain without adding a named binding.\nBoth work and cleanup failures are retained when both fail.\n\n`getOwnedPgPool(owner, name)` supports synchronous construction of existing\napp-owned SQL adapters. It validates the owner/binding and lazily returns the\nsame raw pool used by leases. This is a bootstrap seam: it does not track an\noperation by itself. The application must drain requests and stop its workers\nbefore owner close; the adapter must never call `pool.end()`.\n\nNamed bindings snapshot effective driver settings at configuration time. URI\nfields take the installed pg parser's precedence; `poolOptions.connectionString`\nis rejected to avoid a second target. TLS file contents and ordinary configuration\nobjects are copied. A later conflicting reconfiguration fails with\n`PG_BINDING_CONFLICT`. New connections also reject ambient-default drift before\nopening a socket. Static passwords are pinned and do not trigger a later pgpass\nlookup; explicit password-provider functions retain their identity and rotation\nbehavior. Functions and plain objects/arrays/Buffers are supported; cyclic or\nnon-plain option objects (such as a prebuilt TLS secure context) are rejected.\nThe existing URI `sslmode=require` compatibility behavior is preserved; use the\ndriver's verification modes and trusted CA settings when server verification is\nrequired.\nOmitted URI host/database fields follow pg's configure-time defaults (for example,\ndatabase defaults to the resolved user); those effective values are then pinned.\n\nThe versioned in-process protocol shares **raw pg pools**, never Drizzle database\nor transaction wrappers, across physical package copies. The integration matrix\ncovers pg 8.16.3/8.20.0 and Drizzle 0.45.1/0.45.2. Effective configuration uses pg's\nexported `pg/lib/connection-parameters` resolver; incompatible protocol/config\nshapes fail with `PG_RESOURCE_PROTOCOL_UNSUPPORTED`. Resource errors expose a\nstable `code` and `resourceProtocol` rather than relying on cross-copy\n`instanceof`; their messages contain no connection settings.\n\n## Repository and UnitOfWork factories\n\nUse `bindPgRepositoryConfig(config, lease)` when assembling a plugin's ordinary\nHexagen repository configuration. The logical `drizzlePgBinding` plus an opaque\n`drizzlePgResource` are retained through lazy factories and config copies.\nThe handle is runtime-only: plugin JSON contains the binding name, and the plugin\nfactory captures the lease during `withPgOwner`. A named configuration missing\nits captured handle fails, including when eager initialization is disabled.\n\n`createRepositoryFactory` and `DraBase` use that explicit resource instead of the\nlegacy connector. Supply the same config to\n`new DrizzleUnitOfWork({ repositoryConfig: config })`; repositories continue to\nreceive `IRepositoryContext.drizzleTx` in a transaction. The UoW preserves typed\nEffect failure causes and holds its lease through rollback and client release.\nThe plugin's operation boundary must wrap the complete service call in\n`lease.run`, including query gaps; `DraBase.getDb` only validates/acquires its\nconsumer-local wrapper and is not itself a service-operation boundary.\n\nStop admission and drain full service operations **before releasing repository\nleases**. A repository may enter its lease again at a later `getDb` after an\nawait; releasing that lease early rejects the accepted operation. AuthV2's\ncaptured adapter uses a separate admission lease, with a per-runtime Effect\nmarker for nested calls. Its close drains admission first, then releases the\nrepository leases. An interrupted caller does not release the hold until the\nunderlying Effect and its finalizers actually exit. The app closes its owner\nonly after all such domain runtimes and workers have drained.\n\nPass `runtime: lease` to an `xf-dm-kits` provider (or an equivalent driver-neutral\n`{ identity, assertActive }` runtime handle). Its caches then belong to that\ncaptured runtime rather than the global provider name. Closed or released handles\nreject cached/lazy results; a new runtime needs a new identity. Forward both\nrepository resource fields through domain-specific endpoint/config builders;\n`buildRepositoryConfig` already preserves them.\n\n## Standalone compatibility\n\n`drizzleConnect`, `getDrizzleDb` and `drizzleDisconnect` retain a module-local\nlegacy connection for standalone consumers. Calls omitting URI/options reuse it.\nAn explicitly different URI or supplied options fail with `PG_BINDING_CONFLICT`\ninstead of silently using the first target. Existing standalone pg environment\nand pgpass defaults remain supported. Disconnect affects only that legacy owner;\nit cannot close an application's named bindings. Migrate all repositories of a\nmulti-target host to named bindings before adopting the stricter legacy guard.\n\n## Local validation\n\nBuild first, then run `test:pg` and `test:sqlite`. PostgreSQL tests initialize and\nremove their own temporary native cluster and require `initdb`, `pg_ctl`, and\n`psql` on PATH. They do not use an application database. `test:pg:compat` additionally\nrequires `XF_PG_COMPAT_PATHS` pointing to a JSON inventory of the existing local\ndriver/ORM packages; it performs no package installation.\n\n## License\n\nCopyright (c) 2026 Mehmet Zeki Sönmez.\n\nLicensed under the [**PolyForm Strict License 1.0.0**](https://polyformproject.org/licenses/strict/1.0.0). The license permits noncommercial use and does not grant permission to modify or redistribute the package.\n","readmeFilename":"README.md"}