{"_id":"@arxjs/drizzle","name":"@arxjs/drizzle","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@arxjs/drizzle","version":"0.0.1","description":"Drizzle ORM adapter for @arxjs/core — supports PostgreSQL, MySQL, and SQLite","keywords":["authorization","rbac","drizzle","drizzle-orm","adapter","typescript"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/lcubas/arx.git","directory":"packages/drizzle"},"homepage":"https://github.com/lcubas/arx/tree/main/packages/drizzle#readme","bugs":{"url":"https://github.com/lcubas/arx/issues"},"type":"module","engines":{"node":">=18"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./schema/pg":{"import":{"types":"./dist/schema/pg.d.mts","default":"./dist/schema/pg.mjs"},"require":{"types":"./dist/schema/pg.d.cts","default":"./dist/schema/pg.cjs"}},"./schema/mysql":{"import":{"types":"./dist/schema/mysql.d.mts","default":"./dist/schema/mysql.mjs"},"require":{"types":"./dist/schema/mysql.d.cts","default":"./dist/schema/mysql.cjs"}},"./schema/sqlite":{"import":{"types":"./dist/schema/sqlite.d.mts","default":"./dist/schema/sqlite.mjs"},"require":{"types":"./dist/schema/sqlite.d.cts","default":"./dist/schema/sqlite.cjs"}}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.cts","sideEffects":false,"publishConfig":{"access":"public"},"peerDependencies":{"@arxjs/core":"*","drizzle-orm":">=0.31.0"},"devDependencies":{"@types/node":"*","drizzle-orm":"^0.38.0","tsdown":"^0.21.0","typescript":"^5.7.0","vitest":"^4.0.0","@arxjs/core":"0.0.1"},"scripts":{"build":"tsdown src/index.ts src/schema/pg.ts src/schema/mysql.ts src/schema/sqlite.ts --format esm,cjs --dts --sourcemap --no-splitting --clean --external drizzle-orm --external @arxjs/core","test":"vitest run","typecheck":"tsc --noEmit"},"_id":"@arxjs/drizzle@0.0.1","_integrity":"sha512-UbjzTqxLVcOoFtmHvMEg+4pGJ7GIX/K6+pnn35D9123oazhgPM8WZeAvVzyGL24Z5tPERyEDm+60lkOmLedA7w==","_resolved":"/private/var/folders/s6/wkd256dd3gg23_7vr_h91ckr0000gn/T/f8015d0cec2e08941ff8fc3d23b181cc/arxjs-drizzle-0.0.1.tgz","_from":"file:arxjs-drizzle-0.0.1.tgz","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-UbjzTqxLVcOoFtmHvMEg+4pGJ7GIX/K6+pnn35D9123oazhgPM8WZeAvVzyGL24Z5tPERyEDm+60lkOmLedA7w==","shasum":"652b69de4e022ab7e1630976903025606447589e","tarball":"https://registry.npmjs.org/@arxjs/drizzle/-/drizzle-0.0.1.tgz","fileCount":34,"unpackedSize":234527,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBf8duU+SRaTlW+OWo+qxp41EUcy+d8vqoW4J1Ca72WmAiEAheEMywS+i2OLUS4aAiQheVWk1cpWgpD/tSRXWWQfCLA="}]},"_npmUser":{"name":"lcubas92","email":"langelcubas92@gmail.com"},"directories":{},"maintainers":[{"name":"lcubas92","email":"langelcubas92@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/drizzle_0.0.1_1777099345326_0.25457567828855354"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-25T06:42:25.235Z","0.0.1":"2026-04-25T06:42:25.473Z","modified":"2026-04-25T06:42:25.734Z"},"maintainers":[{"name":"lcubas92","email":"langelcubas92@gmail.com"}],"description":"Drizzle ORM adapter for @arxjs/core — supports PostgreSQL, MySQL, and SQLite","homepage":"https://github.com/lcubas/arx/tree/main/packages/drizzle#readme","keywords":["authorization","rbac","drizzle","drizzle-orm","adapter","typescript"],"repository":{"type":"git","url":"git+https://github.com/lcubas/arx.git","directory":"packages/drizzle"},"bugs":{"url":"https://github.com/lcubas/arx/issues"},"license":"MIT","readme":"# @arxjs/drizzle\n\n[Drizzle ORM](https://orm.drizzle.team/) adapter for [`@arxjs/core`](https://github.com/lcubas/arx/tree/main/packages/core). Supports PostgreSQL, MySQL, and SQLite via dialect-specific adapters.\n\n## Installation\n\n```bash\npnpm add @arxjs/drizzle @arxjs/core drizzle-orm\n# npm install @arxjs/drizzle @arxjs/core drizzle-orm\n```\n\n## Quick start\n\nPick the adapter that matches your database. No schema configuration needed — each adapter bundles its own schema internally.\n\n**PostgreSQL**\n```ts\nimport { drizzle } from 'drizzle-orm/postgres-js'\nimport postgres from 'postgres'\nimport { createAuthorization } from '@arxjs/core'\nimport { DrizzlePgAdapter } from '@arxjs/drizzle'\n\nconst db = drizzle(postgres(process.env.DATABASE_URL))\n\nconst arx = createAuthorization({\n  adapter: new DrizzlePgAdapter(db),\n})\n```\n\n**MySQL**\n```ts\nimport { drizzle } from 'drizzle-orm/mysql2'\nimport mysql from 'mysql2/promise'\nimport { createAuthorization } from '@arxjs/core'\nimport { DrizzleMysqlAdapter } from '@arxjs/drizzle'\n\nconst connection = await mysql.createConnection(process.env.DATABASE_URL)\nconst db = drizzle(connection)\n\nconst arx = createAuthorization({\n  adapter: new DrizzleMysqlAdapter(db),\n})\n```\n\n**SQLite**\n```ts\nimport { drizzle } from 'drizzle-orm/better-sqlite3'\nimport Database from 'better-sqlite3'\nimport { createAuthorization } from '@arxjs/core'\nimport { DrizzleSqliteAdapter } from '@arxjs/drizzle'\n\nconst db = drizzle(new Database('sqlite.db'))\n\nconst arx = createAuthorization({\n  adapter: new DrizzleSqliteAdapter(db),\n})\n```\n\n## Setting up the database tables\n\narx needs five tables in your database. There are two ways to create them.\n\n### Option A — drizzle-kit (recommended)\n\n`drizzle-kit` generates and runs migrations automatically. For it to work, it needs to see the arx tables alongside your own tables in your schema file.\n\n**1. Re-export the arx schema from your schema file**\n\nPick the subpath that matches your dialect and re-export its contents:\n\n```ts\n// src/schema.ts\n\n// Re-export arx tables so drizzle-kit includes them in migrations\nexport * from '@arxjs/drizzle/schema/pg'     // PostgreSQL\n// export * from '@arxjs/drizzle/schema/mysql'  // MySQL\n// export * from '@arxjs/drizzle/schema/sqlite' // SQLite\n\n// Your own tables\nexport const posts = pgTable('posts', {\n  id:    text('id').primaryKey(),\n  title: text('title').notNull(),\n})\n```\n\n> **Why re-export?** drizzle-kit reads your schema file to build a complete picture of your database. If the arx tables aren't visible in your schema, drizzle-kit won't generate migration SQL for them. This is the standard Drizzle pattern for third-party schemas.\n\n**2. Point `drizzle.config.ts` to your schema file**\n\n```ts\n// drizzle.config.ts\nimport { defineConfig } from 'drizzle-kit'\n\nexport default defineConfig({\n  schema: './src/schema.ts',  // your schema file that re-exports arx tables\n  out:    './drizzle',\n  dialect: 'postgresql',\n  dbCredentials: { url: process.env.DATABASE_URL },\n})\n```\n\n**3. Generate and run the migration**\n\n```bash\nnpx drizzle-kit generate   # creates SQL migration files in ./drizzle\nnpx drizzle-kit migrate    # applies the migrations to your database\n```\n\nFor local development, `drizzle-kit push` skips the migration files and applies changes directly:\n\n```bash\nnpx drizzle-kit push\n```\n\n### Option B — manual SQL\n\nIf you manage your own migrations, see the [database schema reference](https://github.com/lcubas/arx/tree/main/packages/core#database-schema) in `@arxjs/core`. It contains a database-agnostic diagram of all five tables with their columns and constraints.\n\n## Usage\n\n```ts\nawait arx.createRole('editor', { permissions: ['post:edit', 'post:view'] })\nawait arx.assignRole('user-1', 'editor')\nawait arx.can('user-1', 'post:edit') // true\n```\n\nSee [`@arxjs/core`](https://github.com/lcubas/arx/tree/main/packages/core) for the full API reference.\n\n## Schema reference\n\nThe arx table definitions are exported from the dialect-specific schema subpaths:\n\n| Subpath | Dialect |\n|---|---|\n| `@arxjs/drizzle/schema/pg` | PostgreSQL |\n| `@arxjs/drizzle/schema/mysql` | MySQL / MariaDB |\n| `@arxjs/drizzle/schema/sqlite` | SQLite |\n\nEach exports five table objects (`roles`, `permissions`, `rolePermissions`, `userRoles`, `userPermissions`) and a `schema` object that bundles all five.\n\n```ts\n// Access individual tables if needed (e.g. for manual queries)\nimport { roles, permissions } from '@arxjs/drizzle/schema/pg'\n```\n\n## Advanced: using the relational query API\n\nDrizzle's relational query API (`db.query.roles.findMany(...)`) requires the schema to be passed to the `drizzle()` constructor. If you want to use this API on arx tables directly, merge the arx schema into your `drizzle()` call:\n\n```ts\nimport { drizzle } from 'drizzle-orm/postgres-js'\nimport * as arxSchema from '@arxjs/drizzle/schema/pg'\nimport * as mySchema from './schema'\n\nconst db = drizzle(client, {\n  schema: { ...arxSchema, ...mySchema },\n})\n\n// Now db.query.roles is typed and available\nconst allRoles = await db.query.roles.findMany()\n```\n\nIn most cases you won't need to query arx tables directly — the adapter handles all of that.\n\n## Advanced: custom table names\n\nIf you need to rename the arx tables (e.g. to avoid conflicts with existing tables), you can extend `DrizzleAdapter` with your own schema object:\n\n```ts\nimport { DrizzleAdapter } from '@arxjs/drizzle'\nimport type { ArxDrizzleSchema } from '@arxjs/drizzle'\nimport { pgTable, primaryKey, text, timestamp } from 'drizzle-orm/pg-core'\n\n// Define renamed versions of the arx tables\nconst myRoles = pgTable('auth_roles', {\n  id:        text('id').primaryKey(),\n  name:      text('name').notNull().unique(),\n  createdAt: timestamp('created_at').notNull().defaultNow(),\n})\n// ... define all five tables\n\nconst customSchema: ArxDrizzleSchema = {\n  roles:           myRoles,\n  permissions:     myPermissions,\n  rolePermissions: myRolePermissions,\n  userRoles:       myUserRoles,\n  userPermissions: myUserPermissions,\n}\n\nclass MyAdapter extends DrizzleAdapter {\n  constructor(db: AnyDrizzleDB) {\n    super(db, customSchema)\n  }\n}\n```\n\n## Peer dependencies\n\n| Package | Version |\n|---|---|\n| `@arxjs/core` | `*` |\n| `drizzle-orm` | `>=0.31.0` |\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-aac306eaf7e58c529673dd0ac38dedc2"}