Anyone successfully use Bun 1.2's Postgres support to connect to a Supabase Postgres database?

I just tried it out, but I am not having much luck. I just followed the happy path sample in the Bun SQL docs:
import { sql } from "bun";

const version = await sql`select version()`;
console.log(version);
import { sql } from "bun";

const version = await sql`select version()`;
console.log(version);
The connection string was provided via the POSTGRES_URL command line variable and was set to the value you get in the Project Settings page when using the Connect button and copying the Direct Connection connection string in the Connection String section tab of the Connect dialog. The DB password was correctly replaced with the placeholder. Trying this I run into this error:
PostgresError: Connection closed
code: "ERR_POSTGRES_CONNECTION_CLOSED"
PostgresError: Connection closed
code: "ERR_POSTGRES_CONNECTION_CLOSED"
Wondering if any fellow Supabase and Bun enjoyers experimented with this and got it to work? I should mention the Supabase support checkbox in the SQL tracking query here is not checked yet: https://github.com/oven-sh/bun/issues/15088 But perhaps that means the Bun folks haven't tried it yet but someone in this community might have? Thank you
4 Replies
garyaustin
garyaustin8mo ago
The direct connection will only work in ipv6 mode from your device,OS,router,network provider to Supabase. You might try the session pooler option which is ipv4 unless you are sure you have ipv6 support. Edit: and just looked at your linked list and no idea on those features without research. Your error implies though you are not even connecting.
Tomas Hubelbauer
Tomas HubelbauerOP8mo ago
This helped me advance past the original error, but now with the Session pooler connection string, the error I get is this:
PostgresError: SSL connection is required
errno: "XX000",
code: "ERR_POSTGRES_SERVER_ERROR"
PostgresError: SSL connection is required
errno: "XX000",
code: "ERR_POSTGRES_SERVER_ERROR"
I tried adding ?sslmode=prefer at the end of the connection string and it gave me this:
PostgresError: Address not in tenant allow_list: {#, #, #, #}
errno: "XX000",
code: "ERR_POSTGRES_SERVER_ERROR"
PostgresError: Address not in tenant allow_list: {#, #, #, #}
errno: "XX000",
code: "ERR_POSTGRES_SERVER_ERROR"
I realized my DB was disallowing all direct connections so I used the https://supabase.com/dashboard/project/_/settings/database Network restrictions section to white-list my IPv4. Thank you
garyaustin
garyaustin8mo ago
No help from me on SSL other than the settings.
No description
Tomas Hubelbauer
Tomas HubelbauerOP8mo ago
Sorry I was typing the message as I was trying things. Ultimately I meant to say you've helped me solve it and what were the steps. I am happy with SSL being enforced and all IPs but my whitelisted one being banned. Now the setup works knowing I need to use the Session Pooler connection string and white-list my IPv4.

Did you find this page helpful?