{"id":21500499,"url":"https://github.com/node-libraries/prisma-accelerate-local","last_synced_at":"2025-04-07T10:19:32.582Z","repository":{"id":210185483,"uuid":"725977908","full_name":"node-libraries/prisma-accelerate-local","owner":"node-libraries","description":"Prisma Accelerate functions locally on your behalf.","archived":false,"fork":false,"pushed_at":"2024-10-15T23:58:34.000Z","size":436,"stargazers_count":41,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T09:04:47.712Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/node-libraries.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2023-12-01T09:18:49.000Z","updated_at":"2025-03-24T07:56:27.000Z","dependencies_parsed_at":"2024-02-04T03:26:22.003Z","dependency_job_id":"6c26a94f-8b06-409d-b71d-b4275e806beb","html_url":"https://github.com/node-libraries/prisma-accelerate-local","commit_stats":null,"previous_names":["node-libraries/prisma-accelerate-local"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-libraries%2Fprisma-accelerate-local","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-libraries%2Fprisma-accelerate-local/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-libraries%2Fprisma-accelerate-local/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-libraries%2Fprisma-accelerate-local/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-libraries","download_url":"https://codeload.github.com/node-libraries/prisma-accelerate-local/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247631834,"owners_count":20970069,"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":[],"created_at":"2024-11-23T17:41:57.032Z","updated_at":"2025-04-07T10:19:32.561Z","avatar_url":"https://github.com/node-libraries.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prisma-accelerate-local\n\nPrisma Accelerate functionality can be self-hosted locally.\n\n## Samples\n\n- Node.js (local)  \n  https://github.com/SoraKumo001/prisma-accelerate-local-test\n- Cloudflare Workers(Postgres) (local)  \n  https://github.com/SoraKumo001/cloudflare-workers-prisma\n- Cloudflare Workers(Postgres) (server)  \n  https://github.com/SoraKumo001/prisma-accelerate-workers\n- Cloudflare Workers(D1) (server)  \n  https://github.com/SoraKumo001/prisma-accelerate-workers-d1\n- Deno(Postgres) (server)  \n  https://github.com/SoraKumo001/prisma-accelerate-deno\n\n## usage\n\n### CLI Options\n\n| Category      | Option                      | Description                                   |\n| ------------- | --------------------------- | --------------------------------------------- |\n| **USAGE**     | [option] _\\\u003curl\u003e_           |                                               |\n| **ARGUMENTS** | _\\\u003curl\u003e_                    | Datasource url                                |\n| **OPTIONS**   | -t, --http                  | Accepted at http                              |\n|               | -p, --port \\\u003cport\u003e          | Port to listen on (default:4000)              |\n|               | -h, --host \\\u003chost\u003e          | Host to listen on (default:localhost)         |\n|               | -c, --cert \\\u003cpath\u003e          | Path to ssl cert file                         |\n|               | -k, --key \\\u003cpath\u003e           | Path to ssl key file                          |\n|               | -w, --wasm                  | Use wasm as the run-time engine(early-access) |\n|               | -s, --secret \\\u003csecret\u003e      | Secret used with API key                      |\n|               | -m, --make                  | make api key                                  |\n|               | -b, --bodyLimit \\\u003csize(MB)\u003e | body limit size(default: 16MB)                |\n\n### CLI\n\n#### Start without setting an API key for local use.\n\n```sh\n# Startup by specifying the Datasource url\nnpx prisma-accelerate-local postgresql://postgres:password@localhost:5432/postgres\n\n# Startup by specifying Port\nnpx prisma-accelerate-local postgresql://postgres:password@localhost:5432/postgres -p 8000\n```\n\n#### When setting the API key\n\n- Create an API key\n\n```sh\nnpx prisma-accelerate-local -s secret -m postgresql://postgres:password@localhost:5432/postgres\n\n# Output\neyJhbGciOiJIUzI1NiJ9.eyJkYXRhc291cmNlVXJsIjoiYSIsImlhdCI6MTcwMzY2NDg1NywiaXNzIjoicHJpc21hLWFjY2VsZXJhdGUifQ.4ruaA1RAT9cD3PACSEVIdUs3i2exKkMpNYGks3hyos4\n```\n\n- Activate with API key enabled.\n\nIf secret is used, the DB address is embedded in the API key\n\n```sh\nnpx prisma-accelerate-local -s secret\n```\n\n### Client Environment Variables\n\n#### With regard to the Node.js configuration.\n\nPlease set the environment variable NODE_TLS_REJECT_UNAUTHORIZED because you are using an unauthenticated certificate.\n\n#### With regard to api_key\n\n- If you are not using `secret`, the api_key can be any string.\n- If you are using `secret`, put `--secret` and the api_key created with `--make` in api_key\n\n#### Example\n\n- .env\n\n```env\nDATABASE_URL=\"prisma://localhost:4000/?api_key=API_KEY\"\nNODE_TLS_REJECT_UNAUTHORIZED=\"0\"\n# To remove the NODE_TLS_REJECT_UNAUTHORIZED warning\nNODE_NO_WARNINGS=\"1\"\n```\n\n## library\n\nIf you call this package as a library, it will look like this.\n\n```ts\nimport { createServer } from 'prisma-accelerate-local';\n\nconst server = createServer({\n  datasourceUrl: 'postgresql://postgres:password@localhost:5432/postgres',\n})\n  .listen({ port: 4000 })\n  .then((url) =\u003e console.log(`🚀  Server ready at ${url} `));\n```\n\n## When self-hosting with Deno Deploy (PostgreSQL)\n\nhttps://github.com/SoraKumo001/prisma-accelerate-deno\n\n```ts\nimport pg from 'npm:pg';\nimport { PrismaPg } from 'npm:@prisma/adapter-pg';\nimport { createHandler, importModule } from 'npm:prisma-accelerate-local/deno';\nimport runtime from 'npm:@prisma/client/runtime/query_engine_bg.postgresql.js';\n\nconst engine = '@prisma/client/runtime/query_engine_bg.postgresql.wasm';\n\nDeno.serve(\n  createHandler({\n    runtime: () =\u003e runtime,\n    secret: Deno.env.get('SECRET')!,\n    queryEngineWasmModule: importModule(engine, import.meta.url),\n    adapter: (datasourceUrl: string) =\u003e {\n      const url = new URL(datasourceUrl);\n      const schema = url.searchParams.get('schema') ?? undefined;\n      const pool = new pg.Pool({\n        connectionString: url.toString() ?? undefined,\n      });\n      return new PrismaPg(pool, {\n        schema,\n      });\n    },\n  })\n);\n```\n\n## When self-hosting with Cloudflare Workers (D1)\n\nhttps://github.com/SoraKumo001/prisma-accelerate-workers-d1\n\n```ts\nimport WASM from '@prisma/client/runtime/query_engine_bg.sqlite.wasm';\nimport { PrismaD1 } from '@prisma/adapter-d1';\nimport { createFetcher } from 'prisma-accelerate-local/workers';\n\nexport type Env = {\n  SECRET: string;\n} \u0026 {\n  [key: string]: D1Database;\n};\n\nexport default {\n  fetch: createFetcher({\n    queryEngineWasmModule: WASM,\n    secret: (env: Env) =\u003e env.SECRET,\n    runtime: () =\u003e require(`@prisma/client/runtime/query_engine_bg.sqlite.js`),\n    adapter: (datasourceUrl: string, env) =\u003e {\n      return new PrismaD1(env[datasourceUrl]);\n    },\n    singleInstance: false,\n  }),\n};\n```\n\n## When self-hosting with Cloudflare Workers (PostgreSQL)\n\nhttps://github.com/SoraKumo001/prisma-accelerate-workers\n\n- package.json\n\nNeed `pg-compat` to patch `pg` to fix it.\n\n```json\n{\n  \"name\": \"prisma-accelerate-workers\",\n  \"version\": \"1.0.0\",\n  \"private\": true,\n  \"type\": \"module\",\n  \"scripts\": {\n    \"deploy\": \"wrangler deploy\",\n    \"dev\": \"wrangler dev\",\n    \"start\": \"wrangler dev\"\n  },\n  \"dependencies\": {\n    \"@prisma/adapter-pg\": \"^5.20.0\",\n    \"@prisma/client\": \"^5.20.0\",\n    \"pg\": \"^8.13.0\",\n    \"prisma-accelerate-local\": \"^1.1.10\"\n  },\n  \"devDependencies\": {\n    \"@cloudflare/workers-types\": \"^4.20241011.0\",\n    \"@types/pg\": \"^8.11.10\",\n    \"pg-compat\": \"^0.0.7\",\n    \"typescript\": \"^5.6.3\",\n    \"wrangler\": \"^3.80.4\"\n  }\n}\n```\n\n- wrangler.toml\n\nSet `nodejs_compat_v2`.\n\n```toml\nname = \"prisma-accelerate-workers\"\nmain = \"src/index.ts\"\nminify = true\ncompatibility_date = \"2024-09-23\"\ncompatibility_flags = [\"nodejs_compat_v2\"]\n\n[placement]\nmode = \"smart\"\n\n[observability]\nenabled = true\n```\n\n- src/index.ts\n\n```ts\nimport { Pool } from 'pg';\nimport { PrismaPg } from '@prisma/adapter-pg';\nimport { createFetcher } from 'prisma-accelerate-local/workers';\nimport WASM from '@prisma/client/runtime/query_engine_bg.postgresql.wasm';\n\nexport type Env = {\n  SECRET: string;\n};\n\nexport default {\n  fetch: createFetcher({\n    runtime: () =\u003e require(`@prisma/client/runtime/query_engine_bg.postgresql.js`),\n    secret: (env: Env) =\u003e env.SECRET,\n    queryEngineWasmModule: WASM,\n    adapter: (datasourceUrl: string) =\u003e {\n      const url = new URL(datasourceUrl);\n      const schema = url.searchParams.get('schema') ?? undefined;\n      const pool = new Pool({\n        connectionString: url.toString() ?? undefined,\n      });\n      return new PrismaPg(pool, {\n        schema,\n      });\n    },\n  }),\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-libraries%2Fprisma-accelerate-local","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-libraries%2Fprisma-accelerate-local","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-libraries%2Fprisma-accelerate-local/lists"}