{"_id":"@antislop/zero-lucid","_rev":"2-7cb8f279d8fcad0a04a5e2dcd57ee2c5","name":"@antislop/zero-lucid","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@antislop/zero-lucid","version":"0.1.0","keywords":["zero","rocicorp","lucid","adonisjs","database","adapter","orm"],"license":"MIT","_id":"@antislop/zero-lucid@0.1.0","maintainers":[{"name":"udeshya-dhungana","email":"eddie@codecrafters.io"},{"name":"rohitpaulk","email":"rohitpaulk@gmail.com"}],"dist":{"shasum":"26a03c40cb71e439bbf165f62ad97b643bd74e1e","tarball":"https://registry.npmjs.org/@antislop/zero-lucid/-/zero-lucid-0.1.0.tgz","fileCount":6,"integrity":"sha512-yYtz37xTDrGlATZfszUWQp1u3XyrbnWKZ83OQsivv457zyeb7Fe57AjFqDMxOExlKD6oC2KfHs5xL+R3cOqt/A==","signatures":[{"sig":"MEQCIFiBwx7hp12MTwikT0FSr8Yh5aSwevTP0zy9k7dorgx7AiA0AXWIIzonF16z7mg95tUzDVw0uUvKTl7ZD4Z4R643jw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10564},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"e0625a4b081b3f64ada9497ac65b84d4d2a9306c","scripts":{"test":"vitest run","build":"tsc","test:watch":"vitest"},"_npmUser":{"name":"udeshya-dhungana","email":"eddie@codecrafters.io"},"_npmVersion":"11.13.0","description":"Adonis Lucid database adapter for Zero server mutators","directories":{},"_nodeVersion":"24.16.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.0.0","@types/pg":"^8.11.0","typescript":"^5.0.0","@rocicorp/zero":"^1.5.0","@adonisjs/lucid":"^22.4.2"},"peerDependencies":{"@rocicorp/zero":">=1.5","@adonisjs/lucid":">=22"},"_npmOperationalInternal":{"tmp":"tmp/zero-lucid_0.1.0_1780916756691_0.38045995650591213","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-06-08T11:05:56.447Z","modified":"2026-06-11T04:07:46.016Z","0.1.0":"2026-06-08T11:05:56.865Z"},"license":"MIT","keywords":["zero","rocicorp","lucid","adonisjs","database","adapter","orm"],"description":"Adonis Lucid database adapter for Zero server mutators","maintainers":[{"email":"eddie@codecrafters.io","name":"udeshya-dhungana"},{"email":"andy@codecrafters.io","name":"andyli-antislop"},{"email":"rohitpaulk@gmail.com","name":"rohitpaulk"}],"readme":"# zero-lucid\n\n[Adonis Lucid](https://lucid.adonisjs.com/) database adapter for [Zero](https://zero.rocicorp.dev/) server mutators.\n\nThis package provides the interface backed by Lucid, so your Zero server mutators run through Lucid's transaction management instead of an independent connection pool. This unlocks proper test isolation: Japa (and similar test frameworks) can wrap each test in a transaction and roll it back afterward, because the mutator and the test share the same Lucid connection.\n\n## Installation\n\n```bash\nnpm install zero-lucid\n```\n\n`@rocicorp/zero` and `@adonisjs/lucid` are peer dependencies — you should already have them installed.\n\n## Usage\n\nDrop `zeroLucid` in wherever you configure your Zero controller:\n\n```ts\nimport db from \"@adonisjs/lucid/services/db\";\nimport { zeroLucid } from \"zero-lucid\";\nimport { schema } from \"./zero/schema.js\";\n\nconst dbProvider = zeroLucid(schema, db);\n```\n\nThen pass `dbProvider` to `handleMutateRequest`:\n\n```ts\nimport { handleMutateRequest } from \"@rocicorp/zero/server\";\n\nawait handleMutateRequest({\n  body: request.body(),\n  dbProvider,\n  handler: (transact) =>\n    transact((tx, name, args) => {\n      const mutator = mustGetMutator(mutators, name);\n      return mutator.fn({ args, ctx, tx });\n    }),\n  query: request.qs(),\n  userID: userId,\n});\n```\n\n## How it works\n\n`zeroLucid` wraps Lucid's `db` service in a `LucidConnection` that implements Zero's `DBConnection` interface. When Zero opens a transaction, it calls `LucidConnection.transaction()`, which delegates to `db.transaction()` — so Lucid owns the connection lifecycle (BEGIN / COMMIT / ROLLBACK).\n\nInside the transaction, a `LucidInternalTransaction` wraps the Lucid `tx` and implements Zero's `DBTransaction` interface. It handles one non-trivial difference between the two: Zero emits PostgreSQL-style `$1, $2` parameter placeholders, but Lucid/Knex expects `?`. The adapter rewrites these before forwarding to `tx.rawQuery()`.\n\n```\nZero calls dbProvider.transaction(fn)\n  → LucidConnection opens a Lucid transaction\n    → LucidInternalTransaction wraps the Lucid tx\n      → your mutator runs, calling tx.run() / tx.mutate.*\n        → Zero compiles ZQL to SQL\n        → LucidInternalTransaction rewrites $1,$2 → ?\n        → Lucid executes the SQL on the open transaction\n  → Lucid commits (or rolls back on error)\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}