{"id":46580113,"url":"https://github.com/m9tdev/effect-prisma-generator","last_synced_at":"2026-03-07T11:01:27.200Z","repository":{"id":325105369,"uuid":"1099771718","full_name":"m9tdev/effect-prisma-generator","owner":"m9tdev","description":"Generate a fully-typed, Effect-native service wrapper for Prisma Client with built-in error handling and transaction support.","archived":false,"fork":false,"pushed_at":"2025-11-28T21:54:25.000Z","size":208,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-30T19:43:47.444Z","etag":null,"topics":["effect","effect-ts","generator","prisma"],"latest_commit_sha":null,"homepage":"https://x.com/m9tdev","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m9tdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-19T12:26:54.000Z","updated_at":"2025-11-28T21:54:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/m9tdev/effect-prisma-generator","commit_stats":null,"previous_names":["m9tdev/effect-prisma-generator"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/m9tdev/effect-prisma-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m9tdev%2Feffect-prisma-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m9tdev%2Feffect-prisma-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m9tdev%2Feffect-prisma-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m9tdev%2Feffect-prisma-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m9tdev","download_url":"https://codeload.github.com/m9tdev/effect-prisma-generator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m9tdev%2Feffect-prisma-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30212103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T09:02:10.694Z","status":"ssl_error","status_checked_at":"2026-03-07T09:02:08.429Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["effect","effect-ts","generator","prisma"],"created_at":"2026-03-07T11:01:11.688Z","updated_at":"2026-03-07T11:01:27.194Z","avatar_url":"https://github.com/m9tdev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Effect Prisma Generator\n\nA Prisma generator that creates a fully-typed, Effect-based service wrapper for your Prisma Client.\n\n## Features\n\n- 🚀 **Effect Integration**: All Prisma operations are wrapped in `Effect` for robust error handling and composability.\n- 🛡️ **Type Safety**: Full TypeScript support with generated types matching your Prisma schema.\n- 🧩 **Dependency Injection**: Integrates seamlessly with Effect's `Layer` and `Context` system.\n- 🔍 **Error Handling**: Automatically catches and wraps Prisma errors into specific typed Effect errors.\n\n## Installation\n\nInstall the generator as a development dependency:\n\n```bash\nnpm install -D effect-prisma-generator\n# or\npnpm add -D effect-prisma-generator\n# or\nyarn add -D effect-prisma-generator\n```\n\n## Configuration\n\nAdd the generator to your `schema.prisma` file:\n\n```prisma\n// prisma/schema.prisma\ngenerator client {\n  provider        = \"prisma-client\"\n  output          = \"./generated\"\n}\n\ngenerator effect {\n  provider = \"effect-prisma-generator\"\n  output   = \"./generated/effect.ts\" // relative to the schema.prisma file\n  clientImportPath = \"./client\" // relative to the output path ^\n}\n```\n\nThen run `prisma generate` to generate the client and the Effect service.\n\n### Recommendation (optional)\n\nAdd the following to your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"paths\": {\n      \"~prisma/*\": [\"./prisma/generated/*\"]\n    }\n  }\n}\n```\n\nThen you can import the generated PrismaService (and PrismaClient) like this:\n\n```typescript\nimport { PrismaClient } from \"~prisma/client\";\nimport { PrismaService } from \"~prisma/effect\";\n```\n\nOtherwise, you can import the generated types like this (adjust the path accordingly):\n\n```typescript\nimport { PrismaClient } from \"../../prisma/generated/client\";\nimport { PrismaService } from \"../../prisma/generated/effect\";\n```\n\n## Usage\n\n### 1. Provide the Layer\n\nInitialize the `PrismaClient` and provide it to the `PrismaService.Default` layer as a `PrismaClientService`.\n\n```typescript\nimport { Effect, Layer } from \"effect\";\nimport { PrismaService, PrismaClientService } from \"~prisma/effect\";\n\n// ... in your program\nconst prisma = new PrismaClient({ adapter });\nconst PrismaLayer = Layer.provide(\n  PrismaService.Default,\n  Layer.succeed(PrismaClientService, prisma),\n);\n```\n\n### 2. Use the Service\n\nAccess the `PrismaService` in your Effect programs.\n\n```typescript\nimport { PrismaService } from \"./generated/effect\";\nimport { Effect } from \"effect\";\n\nconst program = Effect.gen(function* () {\n  const prisma = yield* PrismaService;\n\n  // All standard Prisma operations are available\n  const users = yield* prisma.user.findMany({\n    where: { active: true },\n    select: {\n      id: true,\n      accounts: {\n        select: {\n          id: true,\n        },\n      },\n    },\n  });\n  // users: { id: string, accounts: { id: string }[] }[]\n\n  return users;\n});\n```\n\n## API\n\nThe generated `PrismaService` mirrors your Prisma Client API but returns `Effect\u003cSpecificPrismaResultType, PrismaError, never\u003e` instead of Promises, where `PrismaError` is a specific union type based on the operation (e.g., `PrismaCreateError`, `PrismaUpdateError`, `PrismaFindError`).\n\n### Error Handling\n\nAll operations return an `Effect` that can fail with specific Prisma errors. The generator maps Prisma's error codes to typed Effect errors.\n\nEach operation type (create, update, delete, find, etc.) returns a specific union of possible errors.\n\n#### Available Errors\n\n- `PrismaUniqueConstraintError`\n- `PrismaForeignKeyConstraintError`\n- `PrismaRecordNotFoundError`\n- `PrismaRelationViolationError`\n- `PrismaRelatedRecordNotFoundError`\n- `PrismaTransactionConflictError`\n- `PrismaValueTooLongError`\n- `PrismaValueOutOfRangeError`\n- `PrismaDbConstraintError`\n- `PrismaConnectionError`\n- `PrismaMissingRequiredValueError`\n- `PrismaInputValidationError`\n\nAll errors carry the following context:\n\n```typescript\n{\n  cause: Prisma.PrismaClientKnownRequestError;\n  operation: string; // e.g. \"create\", \"findUnique\"\n  model: string; // e.g. \"User\", \"Post\"\n}\n```\n\n#### Example\n\n```typescript\nimport { PrismaService, PrismaUniqueConstraintError } from \"./generated/effect\";\nimport { Effect } from \"effect\";\n\nconst program = Effect.gen(function* () {\n  const prisma = yield* PrismaService;\n\n  yield* prisma.user\n    .create({\n      data: { email: \"test@example.com\", name: \"Test\" },\n    })\n    .pipe(\n      Effect.catchTag(\"PrismaUniqueConstraintError\", (error) =\u003e\n        Effect.logError(`User with email already exists: ${error.model}`),\n      ),\n    );\n});\n```\n\n### Transactions\n\nThe generated service includes a `$transaction` method that allows you to run multiple operations within a database transaction.\n\n```typescript\nconst program = Effect.gen(function* () {\n  const prisma = yield* PrismaService;\n\n  yield* prisma.$transaction(\n    Effect.gen(function* () {\n      const user = yield* prisma.user.create({ data: { name: \"Alice\" } });\n      yield* prisma.post.create({\n        data: { title: \"Hello\", authorId: user.id },\n      });\n    }),\n  );\n});\n```\n\n### Nested Transactions\n\nThe `$transaction` method supports nesting. If you call `$transaction` within an existing transaction, it will reuse the parent transaction context. If any operation fails, the entire transaction (including the parent) is rolled back.\n\n```typescript\nconst program = Effect.gen(function* () {\n  const prisma = yield* PrismaService;\n\n  yield* prisma.$transaction(\n    Effect.gen(function* () {\n      // Operation 1\n      yield* prisma.user.create({ data: { name: \"Parent\" } });\n\n      // Nested transaction\n      yield* prisma.$transaction(\n        Effect.gen(function* () {\n          // Operation 2\n          yield* prisma.user.create({ data: { name: \"Child\" } });\n        }),\n      );\n    }),\n  );\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm9tdev%2Feffect-prisma-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm9tdev%2Feffect-prisma-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm9tdev%2Feffect-prisma-generator/lists"}