SoraKumo001 / prisma-accelerate-workers-d1

Make Cloudflare D1 database available remotely

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prisma-accelerate-workers

Make Cloudflare D1 database available remotely

Required settings on the Cloudflare Workers side.

Cloudflare Workers Settings/Environment Variables

wrangler.toml

minify = true
compatibility_flags = [ "nodejs_compat" ]

[[kv_namespaces]]
binding = "KV"
id = "xxxxxx"

[[d1_databases]]
binding = "DB"
database_name = "xxxxx"
database_id ="xxxxxxx"

[vars]
SECRET = "**********"

Create API key

npx prisma-accelerate-local -s SECRET -m BINDING_NAME

npx prisma-accelerate-local -s abc -m DB

Client-side configuration

Prior requirements

  • Migration of D1
  • Generate prisma client
import { PrismaClient } from '@prisma/client';

const main = async () => {
	const prisma = new PrismaClient({
		datasourceUrl: 'prisma://xxxxx.workers.dev/?api_key=xxxxxxxx',
	});
	prisma.post.findMany().then((posts) => {
		console.log(posts);
	});
};
main();

About

Make Cloudflare D1 database available remotely


Languages

Language:TypeScript 100.0%