Can you use `createClient` with the Transaction pooler?
In node.js, I'm trying to use
@supabase/supabase-js
's createClient
, however this is in a serverless function so I want to use the Transaction pooler
provided by supabase (https://supabase.com/dashboard/project/_?showConnect=true)
In supabase it says to use this URI: postgres://postgres:[YOUR-PASSWORD]@db.xxxxxxxxxxxxxxx.supabase.co:6543/postgres
But if I pass that to createClient
, it errors saying: Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.
Am I meant to be using a different lib by any chance?8 Replies
You use the API REST URL with createClient.
The ports and poolers are only for direct DB operations.
Ah okay, so I guess I should use something like
pg
?
If you want to do database direct access with or without a pooler you would need a Postgres library and do it only from a server.
Okay fair enough, it's a bit of a shame I can't use superbase-js as now I have to write raw psql queries now, but I gues it is what it is 🙁
?
You can user supabase-js, you just don't use the database ports. You use the API URL. And you don't use SQL.
The REST API for the database has a built in pooler.
Oh right, is there anything I have to do to enable that? I had a look at the opts for createClient but I couldn't see anything
Unless it's something in the dashboard I have to do maybe?
It is always enabled for PostgREST which does the database REST calls.
But you have to do normal REST format or use the SB clients to call it. Not SQL directly.
Ah okay, I was potentially just cooking a bit. I saw in the docs it say for serverless use the Transaction pooler (https://supabase.com/docs/guides/database/connecting-to-postgres#supavisor-transaction-mode), and I just assumed it was recommending that over the REST API, but I guess these are the docs just for direct connection and what you should do only if using direct connections