{"id":14461276,"url":"https://github.com/fdarian/prisma-generator-drizzle","last_synced_at":"2025-08-28T18:32:13.434Z","repository":{"id":212789681,"uuid":"732334014","full_name":"fdarian/prisma-generator-drizzle","owner":"fdarian","description":"A Prisma generator for generating Drizzle schema with ease","archived":false,"fork":false,"pushed_at":"2024-07-14T18:24:54.000Z","size":1382,"stargazers_count":141,"open_issues_count":12,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-14T09:36:06.641Z","etag":null,"topics":["drizzle","drizzle-orm","generator","prisma"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fdarian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-16T10:31:43.000Z","updated_at":"2024-12-13T23:11:27.000Z","dependencies_parsed_at":"2024-04-02T13:26:50.946Z","dependency_job_id":"f7a8040c-0430-49e0-971b-06dc34c3ba4c","html_url":"https://github.com/fdarian/prisma-generator-drizzle","commit_stats":null,"previous_names":["farreldarian/prisma-generator-drizzle","fdarian/prisma-generator-drizzle"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdarian%2Fprisma-generator-drizzle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdarian%2Fprisma-generator-drizzle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdarian%2Fprisma-generator-drizzle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdarian%2Fprisma-generator-drizzle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fdarian","download_url":"https://codeload.github.com/fdarian/prisma-generator-drizzle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231294144,"owners_count":18354140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drizzle","drizzle-orm","generator","prisma"],"created_at":"2024-09-01T21:02:27.096Z","updated_at":"2024-12-25T23:30:29.693Z","avatar_url":"https://github.com/fdarian.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# prisma-generator-drizzle\n\n[![Test](https://github.com/farreldarian/prisma-generator-drizzle/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/farreldarian/prisma-generator-drizzle/actions/workflows/test.yml)\n\n**prisma-generator-drizzle** is a [Prisma](https://www.prisma.io/) generator that allows you to generate [Drizzle](https://orm.drizzle.team/) schema definitions from Prisma schema. It provides 1:1 functionality mapping, allowing you to use Drizzle as a drop-in replacement for querying and mutating your database. \n\nThis tool is ideal for projects transitioning from Prisma to Drizzle, or for those wanting to use both Prisma and Drizzle together. Leveraging the DX of Prisma for defining your schema while still getting the performance benefits and flexibility of Drizzle.\n\n### Features\n\nhttps://github.com/farreldarian/prisma-generator-drizzle/assets/62016900/35b57135-614e-4e07-920b-9e9a487eb6cb\n\n- 🤝 **Compatibility**: 1:1 Prisma to Drizzle schema generation*\n- ✅ **Relational Query Support**: Generates relational query definitions.  \n- 📦 **Cutomizability**: Includes tools for customizing drizzle-specific features.\n\n_\\*Only supports default scalar for now and more constraints will be added in future_\n\n\u003e Note: This project is still considered experimental, but you can safely use it for production. Follow the progress on [v1](https://github.com/farreldarian/prisma-generator-drizzle/issues/1).\n\n\n## Getting started\n\n### 1. Install the package\n\n```bash\nnpm install -D prisma-generator-drizzle\nnpm install drizzle-orm\n```\n\n### 2. Add to your Prisma schema\n\n```prisma\ngenerator drizzle {\n  provider = \"prisma-generator-drizzle\"\n  // Specify the output file (or directory)\n  output = \"./infra/database/drizzle.ts\"\n}\n```\n\n\u003e See [configuration](#configuration) for more options.\n\n### 3. Run the generator\n\n```bash\nprisma generate\n```\n\n\n### Learn More\n- [Compatibility](#compatibility)\n- [Usages](#usages)\n  - [configuration](#configuration)\n  - [drizzle-kit](#setting-up-drizzle-kit)\n  - [relational query](#setting-up-relational-query)\n- [Experimental](#experimental)\n  - [Customize field with `drizzle.custom`](#customize-field-with-drizzlecustom)\n- [Compatibility](#compatibility)\n- [Examples](#examples) \n- [Gotchas](#gotchas)\n\n## Usages\n\n### Configuration\n\n| Key             | Description                       | Default     | Example     |\n| --------------- | --------------------------------- | ----------- | ----------- |\n| output          | Generate output directory                 | \"./drizzle\" | \"../models\" |\n|    | Generate single output file                 |  | \"drizzle.ts\" |\n| formatter       | Run formatter after generation     | -           | \"prettier\"  |\n| relationalQuery | Flag to generate relational query | true        | false       |\n| moduleResolution         | Specify the [module resolution](https://www.typescriptlang.org/tsconfig#moduleResolution) that will affect the import style | _*auto_           | nodenext        |\n| verbose         | Flag to enable verbose logging    | -           | true        |\n| abortOnFailedFormatting | Flag to throw exception when formatting fails | true | false |\n| **dateMode | Change the generated mode for date | \"date\" ||\n\n_* It will find the closest tsconfig from the current working directory. Note that [extends](https://www.typescriptlang.org/tsconfig#extends) is not supported_\n\n_**Does not work with sqlite_\n\n### Setting up [relational query](https://orm.drizzle.team/docs/rqb)\n\n```ts\nimport { drizzle } from 'drizzle-orm/node-postgres'\n\n// `schema` contains all table and relation definitions\nimport { schema } from 'prisma/drizzle/schema'\n\nconst client = ... // database client\nconst db = drizzle(client, { schema })\n```\n\n### Setting up [drizzle-kit](https://orm.drizzle.team/kit-docs/overview)\n\nUse the glob pattern (see [example 3](https://orm.drizzle.team/kit-docs/conf#schema-files-paths)) to reference the generated table definitions.\n\n```ts\nimport { defineConfig } from 'drizzle-kit'\nexport default defineConfig({\n  // Using the default output path\n  schema: './prisma/drizzle/*',\n})\n```\n\n## Experimental\n\nThese syntaxes might change in the future, we encourage your feedback.\n\nWe will make sure to keep the syntaxes compatible with future versions.\n\n### Customize field with `drizzle.custom` \n\nCustomize the generated field definition using `drizzle.custom` directive in a json format.\n\nThis will override any built-in mapping such as `@default(...)` or `@db.*` modifiers.\n\nAvailable options:\n\n```prisma\nmodel Table {\n  /// drizzle.custom {\n  ///   \"imports\": [{ \"name\": [\"UserId\"], \"module\": \"~/models/user\", \"type\": true }],\n  ///   \"$type\": \"UserId\",\n  ///   \"default\": \"() =\u003e 1\",\n  ///   \"field\": { \"mode\": \"number\" }\n  /// }\n  column BigInt\n}\n```\n\n1. `imports`: Specify the import path for the custom code.\n\n   Array of imports that will be added to each schema file.\n\n   - named import: `[{ \"name\": [\"\u003cexported-names\u003e\"], \"module\": \"\u003cpath-or-module\u003e\u003e\" }, ...]`\n   - default import: `[{ \"name\": \"\u003cexported-default\u003e\", \"module\": \"\u003cpath-or-module\u003e\u003e\" }, ...]` \n   - type import: `[{ ..., \"type\": true }, ...]`\n\n   [[definition]](https://github.com/fdarian/prisma-generator-drizzle/blob/e25318bf38ad4d20bb3da4c64f0e1b275d4b007f/packages/generator/src/lib/adapter/fields/directives/custom.ts#L38)\n  \n\n2. `$type`: Specify the type to use for the field.\n3. `default`: Specify the default value for the field.\n4. 🏗️ `field`: Specify the field options.\n\n\u003e NOTE: All options are optional. Items marked with 🏗️ are incomplete\n\n### Generate [`.$defaultFn()`](https://arc.net/l/quote/cmywscsv) Custom Default Initializer\n\n\u003e ⚠️ This may potentially be removed and replaced by `drizzle.custom` directive\n\nAdd `/// drizzle.default \u003cmodule\u003e::\u003cnamed-function-import\u003e` directive above the field definition to generate a custom default initializer.\n\n\u003e NOTE: This will override any `@default(...)` attribute from the schema.\n\n```prisma\nmodel User {\n  /// drizzle.default @paralleldrive/cuid2::createId\n  id     String @id\n  ...\n}\n```\n\nThis will result to:\n\n```ts\nimport { createId } from '@paralleldrive/cuid2'\n...\n\nexport const users = pgTable('User', {\n  id: text('id')\n    .$defaultFn(() =\u003e createId())\n    .primaryKey(),\n  ...\n})\n```\n\nOr with a custom code\n\n```prisma\nmodel User {\n  /// drizzle.default crypto::randomBytes `() =\u003e randomBytes(16).toString('hex')`\n  salt      String?\n  ...\n}\n```\n\n```ts\nimport { randomBytes } from 'node:crypto'\n...\n\nexport const users = pgTable('User', {\n  salt: text('salt')\n    .$defaultFn(() =\u003e randomBytes(16).toString('hex'))\n    .notNull(),\n  ...\n})\n```\n\n### Generate [`.$type\u003c..\u003e()`](https://orm.drizzle.team/docs/column-types/mysql#customizing-column-data-type) Type Customization\n\n\n\u003e ⚠️ This may potentially be removed and replaced by `drizzle.custom` directive\n\n\nAdd `/// drizzle.type \u003cmodule\u003e::\u003cnamed-import\u003e` directive above the field definition.\n\n```prisma\nmodel Wallet {\n  /// drizzle.type viem::Address\n  address     String?\n  ...\n}\n```\n\nThis will result to:\n\n```ts\nimport { Wallet } from 'viem'\n...\n\nexport const wallets = pgTable('Wallet', {\n  address: text('address').$type\u003cAddress\u003e(),\n  ...\n})\n```\n\nOr with a relative import\n\n```prisma\nmodel User {\n  /// drizzle.type ../my-type::Email\n  email     String?\n  ...\n}\n```\n\n```ts\nimport { Email } from '../my-type'\n...\n\nexport const users = pgTable('User', {\n  email: text('email').$type\u003cEmail\u003e(),\n  ...\n})\n```\n\n\n## Compatibility\n\n**prisma-generator-drizzle** aims for 1:1 compatibility with Prisma, this means that you can use the generated Drizzle schema as a complete and familiar drop-in replacement for the Prisma client.\n\n\u003e **Note:** This generator will use the [default Prisma field mapping](https://www.prisma.io/docs/orm/reference/prisma-schema-reference#model-field-scalar-types), meaning any `@db.*` modifiers will be ignored for now.\n\n\n### Postgres\n  1. String [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L73)\n  2. Boolean [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L89)\n  3. Int [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L129) \n  4. BigInt [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L73)\n  5. Float [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L121)\n  6. Decimal [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L113)\n  7. JSON [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L145)\n  8. Bytes [\\[def\\]](https://github.com/fdarian/prisma-generator-drizzle/blob/672f0aa99f3a86f0c0ab138728932f5cb13cfb83/packages/generator/src/lib/adapter/providers/postgres.ts#L97)  \n\n  #### Unsupported:\n  1. Unsupported (🏗️ soon)\n\n### MySQL\n  \u003e todo docs\n### SQLite\n  \u003e todo docs\n\n\n## Examples\n1. [with-drizzle-prisma](./examples/with-drizzle-prisma/): using drizzle's prisma extension\n\n\n## Gotchas\n### Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'.\n\nBy default, the generator will try to find the closest tsconfig from the current working directory to determine the import style, whether to add `.js` or not. When there's no config found, it will use the common import (e.g. `import { users } from './users'`).\n\nYou can explicitly set the `moduleResolution` option in the [generator configuration](#configuration).\n\nCheck also [the discussion](https://github.com/farreldarian/prisma-generator-drizzle/issues/18)\n\n### SqliteError: NOT NULL constraint failed: \\\u003ctable-name\\\u003e.id\n\nCurrently having `@default(autoincrement())` only work for postgres and mysql.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdarian%2Fprisma-generator-drizzle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffdarian%2Fprisma-generator-drizzle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdarian%2Fprisma-generator-drizzle/lists"}