Make Cloudflare D1 database available remotely
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 = "**********"
npx prisma-accelerate-local -s SECRET -m BINDING_NAME
npx prisma-accelerate-local -s abc -m DB
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();