Docs unclear on connection pool vs. direct connection

In the docs under "Supabase" it teaches you how to setup Drizzle w/ supabase. The last part shows how to set up the connection:
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import { users } from './schema'

const connectionString = process.env.DATABASE_URL
const client = postgres(connectionString)
const db = drizzle(client);

const allUsers = await db.select().from(users);
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import { users } from './schema'

const connectionString = process.env.DATABASE_URL
const client = postgres(connectionString)
const db = drizzle(client);

const allUsers = await db.select().from(users);
But underneath it simply says: Connect to your database using the Connection Pooler for serverless environments, and the Direct Connection for long-running servers. I'm assuming the code above is for Direct Connection? If that is the case, why is there no implementation demonstration for the Connection Pooler? Also isn't Supabase always going to be serverless? Maybe I'm missing something but this just feels confusing
10 Replies
Angelelz
Angelelz16mo ago
I guess you're right. Would you like to open an issue in GitHub for this?
zendev
zendevOP16mo ago
Sure I’ll do this In the meantime tho, how do you set up drizzle with serverless supabase?
Angelelz
Angelelz16mo ago
Use a pool as it's recommended
rphlmr ⚡
rphlmr ⚡16mo ago
Maybe I am dumb but I can't make pooler url working with Supabase. It always ends on errors when my code runs. Afaik, postgressjs handles pooler. You just have to choose the good connection string.
rphlmr ⚡
rphlmr ⚡16mo ago
Read carefully if you use prepared statements, the default pool mode on Supabase is "transaction" and doesn't handle them.
zendev
zendevOP16mo ago
Looks like a connection pooler is the way to go according to this Any luck resolving this?
rphlmr ⚡
rphlmr ⚡16mo ago
I opened a ticket and no clear answer What happen to me: deploying 3 instances on fly.io (docker containers), few minutes later everything is done with cryptic errors related to pooler I chatted with someone with the same issue
zendev
zendevOP16mo ago
Is the Drizzle team aware of this? I’m sure there are tons of ppl using Drizzle w serverless Postgres dbs so I’m guessing we’re just missing something?
rphlmr ⚡
rphlmr ⚡16mo ago
This is at least a driver issue or a Supabase issue 🥶 Or this is just me 😂
Want results from more Discord servers?
Add your server