P
Prisma6mo ago
uc

how to setup connection pooling string in hono

where do i put connectionpooling_url in .env or in wrangler.json. and where to put DATABASE_url from postgres i try to put both of them in .env connectionpooling_url as DATABASE_URL and database_url as DIRECT_URL and it worked npx prisma migrate and generate was working but the tutorial i am following is explaining how to setup at production level but the problem is that it is 1 year old and things have change he was telling to put url in wrangler.toml but i don't have it i have wrangler.jsonc so what did i do wrong and how do i setup ?
1 Reply
Prisma AI Help
Prisma AI Help6mo ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. To set up connection pooling with Prisma in a Hono (Cloudflare Workers) project, you need to manage your environment variables for both development and production. Here’s how you should do it based on the latest Prisma documentation and community guidance: 1. Environment Variables - DATABASE_URL: This should be your connection pooling URL (e.g., from Prisma Accelerate, Neon Pooler, or Supabase Pooler). - DIRECT_URL: This should be your direct Postgres connection string, used for migrations and CLI commands. Your .env file should look like this:
DATABASE_URL="your_connection_pooling_url"
DIRECT_URL="your_direct_postgres_url"
DATABASE_URL="your_connection_pooling_url"
DIRECT_URL="your_direct_postgres_url"
This setup allows npx prisma migrate and npx prisma generate to work correctly, as you’ve already observed. The DATABASE_URL is used by your deployed app (via the pooler), and DIRECT_URL is used by the CLI for direct DB access during migrations and introspection see example here. 2. Production Deployment (Cloudflare Workers) - wrangler.toml is now often replaced by wrangler.json or wrangler.jsonc. You should set your production environment variables (like DATABASE_URL) in your wrangler.jsonc under the env or vars section, depending on your deployment target. - Hono/Cloudflare Workers do not read from .env at runtime. You must set the DATABASE_URL in your wrangler.jsonc for production. Example wrangler.jsonc:
{
"env": {
"DATABASE_URL": "your_connection_pooling_url"
}
}
{
"env": {
"DATABASE_URL": "your_connection_pooling_url"
}
}
3. Summary - Use .env for local development and Prisma CLI. - Use wrangler.jsonc for production, setting only the DATABASE_URL (the pooling URL). - DIRECT_URL is only needed locally for migrations, not in production. This approach is up-to-date and matches current best practices. If you follow this, you’re not doing anything wrong—just adapting to t he new config file format (wrangler.jsonc instead of wrangler.toml) and the way environment variables are handled in Cloudflare Workers and Hono see discussion. If you need more details on the Prisma side, see Prisma docs on environment variables. ✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?