{"_id":"@a77ay/better-auth-mikro-orm","_rev":"2-3768aa5fbccd1cd590883a58ac4d42c0","name":"@a77ay/better-auth-mikro-orm","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@a77ay/better-auth-mikro-orm","version":"0.1.0","keywords":["adapter","auth","authentication","better-auth","better-auth-adapter","generator","mikro-orm","mikroorm","schema-generator"],"author":{"url":"https://github.com/A77AY","name":"A77AY"},"license":"MIT","_id":"@a77ay/better-auth-mikro-orm@0.1.0","maintainers":[{"name":"krickray","email":"krickray@gmail.com"}],"homepage":"https://github.com/A77AY/better-auth-mikro-orm#readme","bugs":{"url":"https://github.com/A77AY/better-auth-mikro-orm/issues"},"bin":{"better-auth-mikro-orm":"./dist/cli.mjs"},"dist":{"shasum":"5b1c95a76a306189e108e325f7219f6d0619f32d","tarball":"https://registry.npmjs.org/@a77ay/better-auth-mikro-orm/-/better-auth-mikro-orm-0.1.0.tgz","fileCount":8,"integrity":"sha512-ipPEX+kUjUeAUIOmh2JNnHqgtdNwtLuH+xXIUlHrebTMAGRVI5I5x5sMCB0bdSJ8vtdF65XJ561WeYk65XBHmQ==","signatures":[{"sig":"MEUCIQDSeeFEcxXObomQqadMa8/Z5sCayfCbiUYpchkhA8eJ+AIgIOa3AkKdG8Ze0CZN+us0dn5opQ3QFGwcnpvJOaFiCKU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":61102},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./cli":"./dist/cli.mjs","./package.json":"./package.json"},"scripts":{"dev":"vp pack --watch","test":"vp test","build":"vp pack","check":"vp check","release":"changeset publish","changeset":"changeset","test:coverage":"vp test --coverage","version-packages":"changeset version"},"_npmUser":{"name":"krickray","email":"krickray@gmail.com"},"devEngines":{"packageManager":{"name":"pnpm","onFail":"download","version":"11.24.0"}},"repository":{"url":"git+https://github.com/A77AY/better-auth-mikro-orm.git","type":"git"},"description":"MikroORM database adapter and entity generator for Better Auth.","directories":{},"_nodeVersion":"24.20.0","dependencies":{"jiti":"^2.7.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.23.0","vite":"npm:@voidzero-dev/vite-plus-core@0.3.0","@types/pg":"^8.23.1","vite-plus":"0.3.0","typescript":"^7.0.2","@types/node":"^26.4.0","better-auth":"^1.7.2","@changesets/cli":"^3.0.1","@mikro-orm/core":"^7.1.14","@mikro-orm/sqlite":"^7.1.14","@mikro-orm/mongodb":"^7.1.14","@vitest/coverage-v8":"^4.1.11","@mikro-orm/postgresql":"^7.1.14","@better-auth/test-utils":"^1.7.2","@changesets/changelog-github":"^1.0.0"},"peerDependencies":{"better-auth":"^1.0.0","@mikro-orm/core":"^7.0.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-mikro-orm_0.1.0_1788030152103_0.9433449818543977","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@a77ay/better-auth-mikro-orm","version":"0.1.1","description":"MikroORM database adapter and entity generator for Better Auth.","keywords":["adapter","auth","authentication","better-auth","better-auth-adapter","generator","mikro-orm","mikroorm","schema-generator"],"homepage":"https://github.com/A77AY/better-auth-mikro-orm#readme","bugs":{"url":"https://github.com/A77AY/better-auth-mikro-orm/issues"},"license":"MIT","author":{"name":"A77AY","url":"https://github.com/A77AY"},"repository":{"type":"git","url":"git+https://github.com/A77AY/better-auth-mikro-orm.git"},"bin":{"better-auth-mikro-orm":"./dist/cli.mjs"},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs","./cli":"./dist/cli.mjs","./package.json":"./package.json"},"publishConfig":{"access":"public"},"dependencies":{"jiti":"^2.7.0"},"devDependencies":{"@better-auth/test-utils":"^1.7.2","@changesets/changelog-github":"^1.0.0","@changesets/cli":"^3.0.1","@mikro-orm/core":"^7.1.14","@mikro-orm/mongodb":"^7.1.14","@mikro-orm/postgresql":"^7.1.14","@mikro-orm/sqlite":"^7.1.14","@types/node":"^26.4.0","@types/pg":"^8.23.1","@vitest/coverage-v8":"^4.1.11","better-auth":"^1.7.2","pg":"^8.23.0","typescript":"^7.0.2","vite":"npm:@voidzero-dev/vite-plus-core@0.3.0","vite-plus":"0.3.0"},"peerDependencies":{"@mikro-orm/core":"^7.0.0","better-auth":"^1.0.0"},"devEngines":{"packageManager":{"name":"pnpm","version":"11.24.0","onFail":"download"}},"scripts":{"build":"vp pack","dev":"vp pack --watch","test":"vp test","test:coverage":"vp test --coverage","check":"vp check","changeset":"changeset","version-packages":"changeset version","release":"changeset publish"},"_nodeVersion":"24.20.0","_id":"@a77ay/better-auth-mikro-orm@0.1.1","dist":{"integrity":"sha512-WT0EwaIwG6TI0crFDD5bzF823p2o4qMVgSCDFqqzw2pdWSA0TzSVTL8GGjUxNTiPFgOVjFc/GLQnKSYVjnQaPg==","shasum":"8694798fc3d2f91749e826a10bb02ea277749627","tarball":"https://registry.npmjs.org/@a77ay/better-auth-mikro-orm/-/better-auth-mikro-orm-0.1.1.tgz","fileCount":8,"unpackedSize":61102,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@a77ay%2fbetter-auth-mikro-orm@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDL3OGs6/l2O7yTrhXEa2zzEgMjvTC4ZWTsp5ZzfFjE7wIhAJx9MMIOD/ZWNl7ufncuP8hdJonGJPAlZYm9jcbexRPr"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:2fe67e41-6618-43d1-abf0-1ad9cf11efeb"}},"directories":{},"maintainers":[{"name":"krickray","email":"krickray@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/better-auth-mikro-orm_0.1.1_1788031840304_0.910294107502005"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-29T19:02:31.727Z","modified":"2026-08-29T19:30:40.746Z","0.1.0":"2026-08-29T19:02:32.241Z","0.1.1":"2026-08-29T19:30:40.445Z"},"bugs":{"url":"https://github.com/A77AY/better-auth-mikro-orm/issues"},"author":{"name":"A77AY","url":"https://github.com/A77AY"},"license":"MIT","homepage":"https://github.com/A77AY/better-auth-mikro-orm#readme","keywords":["adapter","auth","authentication","better-auth","better-auth-adapter","generator","mikro-orm","mikroorm","schema-generator"],"repository":{"type":"git","url":"git+https://github.com/A77AY/better-auth-mikro-orm.git"},"description":"MikroORM database adapter and entity generator for Better Auth.","maintainers":[{"name":"krickray","email":"krickray@gmail.com"}],"readme":"# @a77ay/better-auth-mikro-orm\n\nMikroORM database adapter and entity generator for [Better Auth](https://www.better-auth.com).\n\n[**🔌 Database Adapter**](#1-adapter-setup) &nbsp;•&nbsp; [**⚡ CLI Entity Generator**](#2-schema--entity-generation)\n\n[![npm version](https://img.shields.io/npm/v/@a77ay/better-auth-mikro-orm.svg?color=blue&logo=npm&logoColor=white)](https://www.npmjs.com/package/@a77ay/better-auth-mikro-orm)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/@a77ay/better-auth-mikro-orm.svg?logo=vite&logoColor=white)](https://bundlephobia.com/package/@a77ay/better-auth-mikro-orm)\n[![Tests](https://img.shields.io/github/actions/workflow/status/A77AY/better-auth-mikro-orm/ci.yml?branch=main&label=550%2B%20tests&logo=github&logoColor=white)](https://github.com/A77AY/better-auth-mikro-orm/actions/workflows/ci.yml)\n[![codecov](https://img.shields.io/codecov/c/github/A77AY/better-auth-mikro-orm?logo=codecov&logoColor=white)](https://codecov.io/gh/A77AY/better-auth-mikro-orm)\n\n## Features\n\n- 🔌 **Native MikroORM Adapter**: Seamlessly integrates with MikroORM's `EntityManager`, Identity Map, and Unit of Work.\n- ⚡ **Entity & Schema Generator**: Generate MikroORM entities compatible with Better Auth core and all active plugins.\n- 🗄️ **Multi-Database Support**: Full support for PostgreSQL, MySQL, MariaDB, SQLite, LibSQL, MongoDB, and custom drivers.\n- 🚀 **Optimized Relations**: Batched queries for joined relations to prevent N+1 issues.\n- 🔒 **Type-Safe**: Complete TypeScript support with automatic type inference.\n\n## Installation\n\n```bash\n# Using npm\nnpm install @a77ay/better-auth-mikro-orm @mikro-orm/core\n\n# Using pnpm\npnpm add @a77ay/better-auth-mikro-orm @mikro-orm/core\n\n# Using yarn\nyarn add @a77ay/better-auth-mikro-orm @mikro-orm/core\n\n# Using bun\nbun add @a77ay/better-auth-mikro-orm @mikro-orm/core\n```\n\n## Compatibility\n\n| `@a77ay/better-auth-mikro-orm` | `better-auth` | `@mikro-orm/core` |\n| ------------------------------ | ------------- | ----------------- |\n| `0.x` (latest)                 | `^1.7.0`      | `^7.0.0`          |\n\n## Quick Start\n\n### 1. Adapter Setup\n\n```typescript\nimport { betterAuth } from \"better-auth\";\nimport { mikroOrmAdapter } from \"@a77ay/better-auth-mikro-orm\";\nimport { orm } from \"./mikro-orm.config\";\n\nexport const auth = betterAuth({\n  database: mikroOrmAdapter(orm),\n});\n```\n\nPass your `MikroORM` instance, `EntityManager`, or a getter function. When passing `orm`, the adapter automatically uses `RequestContext.getEntityManager()` per HTTP request and falls back to `orm.em` for CLI commands and background scripts.\n\n### 2. Schema / Entity Generation\n\n#### Running the Generator\n\nUse the package CLI to generate individual entity files and an `index.ts` barrel export:\n\n```bash\n# Using npx\nnpx @a77ay/better-auth-mikro-orm generate \\\n  --config ./src/auth.ts \\\n  --output ./src/entities/auth \\\n  --yes\n\n# Using pnpm\npnpm exec @a77ay/better-auth-mikro-orm generate \\\n  --config ./src/auth.ts \\\n  --output ./src/entities/auth \\\n  --yes\n```\n\n#### Register in MikroORM\n\nThe generated `index.ts` exports each entity and a `betterAuthEntities` array. Register that array in your MikroORM configuration:\n\n```typescript\nimport { betterAuthEntities } from \"./src/entities/auth\";\n\nexport default {\n  entities: [...betterAuthEntities],\n};\n```\n\nEvery Better Auth model must be registered as a MikroORM entity. Its `tableName` must match the\ncorresponding Better Auth model name (including configured model renames or pluralization).\n\nThe adapter handles data access and transactions; MikroORM migrations remain responsible for creating\nand updating the database schema. After generating entities, use MikroORM's migration tooling to create\nand apply the database migration.\n\n#### CLI Flags\n\n- `--config <path>`: Better Auth config (default: `./src/auth.ts`).\n- `--output <path>`: Output directory (default: `src/entities/auth`).\n- `--style <style>`: `define-entity` or `decorators`; overrides the adapter option.\n- `--casing <casing>`: `camelCase` or `snake_case`; overrides the adapter option.\n- `--file-suffix <suffix>`: Custom entity file suffix (e.g. `.entity` for `user.entity.ts`); overrides the adapter option.\n- `--yes`: Overwrite generated files. Without it, existing generated files are protected.\n\n#### Configuring Defaults in `auth.ts`\n\nInstead of passing CLI flags every time, generator options such as `entityStyle`, `casing`, `fileSuffix`, and the default output `directory` can be configured directly in `mikroOrmAdapter`:\n\n```typescript\nexport const auth = betterAuth({\n  database: mikroOrmAdapter(orm, {\n    entityStyle: \"define-entity\", // \"define-entity\" (default) | \"decorators\"\n    casing: \"snake_case\", // \"snake_case\" | \"camelCase\" (default)\n    directory: \"src/entities/auth\", // Default CLI output directory\n    fileSuffix: \".entity\", // Optional file suffix: user.entity.ts (default: \"\")\n  }),\n});\n```\n\n#### Single-File Generation (Official Better Auth CLI)\n\nIf you prefer generating a single schema file instead of a modular directory, you can use the official Better Auth CLI:\n\n```bash\n# Using npx\nnpx auth@latest generate \\\n  --config ./src/auth.ts \\\n  --output ./src/entities/auth.ts \\\n  --yes\n\n# Using pnpm\npnpm dlx auth@latest generate \\\n  --config ./src/auth.ts \\\n  --output ./src/entities/auth.ts \\\n  --yes\n```\n\nThe adapter exposes the official Better Auth `createSchema` hook used by this command.\n\n## Configuration Options\n\nThe `mikroOrmAdapter` accepts the database instance or getter as its first argument and an optional `options` object as its second argument:\n\n```typescript\nmikroOrmAdapter(em, options?)\n```\n\n| Parameter / Option | Type                                                 | Default                  | Description                                                                             |\n| ------------------ | ---------------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------- |\n| `em` (1st arg)     | `MikroORM \\| EntityManager \\| (() => EntityManager)` | **Required**             | MikroORM instance, `EntityManager`, or getter returning the request-scoped instance.    |\n| `provider`         | `DatabaseProvider`                                   | Auto-detected            | Database provider (`\"postgresql\"`, `\"sqlite\"`, `\"mysql\"`, `\"mongodb\"`, or custom).      |\n| `casing`           | `\"snake_case\" \\| \"camelCase\"`                        | `\"camelCase\"`            | Naming convention for generated database columns.                                       |\n| `entityStyle`      | `\"define-entity\" \\| \"decorators\"`                    | `\"define-entity\"`        | Entity definition style (`defineEntity` fluent schema or `@Entity()` class decorators). |\n| `fileSuffix`       | `string`                                             | `\"\"`                     | Custom file suffix for entity files (e.g. `\".entity\"` generates `user.entity.ts`).      |\n| `directory`        | `string`                                             | `\"src/entities/auth\"`    | Default output directory used by the package CLI.                                       |\n| `schemaFile`       | `string`                                             | `\"src/entities/auth.ts\"` | Default output file path for CLI schema generation.                                     |\n| `debugLogs`        | `boolean \\| DBAdapterDebugLogOption`                 | `false`                  | Enable Better Auth adapter debug logging.                                               |\n| `usePlural`        | `boolean`                                            | `false`                  | Use plural table names for generated entities.                                          |\n| `transactions`     | `boolean`                                            | `true`                   | Whether to execute multi-operation callbacks in a transaction.                          |\n\n## Development\n\nThis project uses [Vite+](https://viteplus.dev) for tooling:\n\n- Install dependencies:\n\n  ```bash\n  vp install\n  ```\n\n- Run tests (SQLite in-memory):\n\n  ```bash\n  vp test\n  ```\n\n- Type check, lint and format:\n\n  ```bash\n  vp check\n  ```\n\n- Build library:\n  ```bash\n  vp pack\n  ```\n\n## License\n\n[MIT](LICENSE) © [A77AY](https://github.com/A77AY)\n","readmeFilename":""}