© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
4 replies
peppermint

Supabase postgres() & createClient() connection both in the same node server

Hello,

Question: Is this a good thing to do? Which of the one method is recommended if this is a bad idea. Please let me know.

Overview :
I have create the below file
db.connect.ts
db.connect.ts
where I have exported both direct connect & api connect methods.
// API Connect
const { supabaseUrl, supabaseKey } = config.dbConfig;
export const supabase = createClient(supabaseUrl!, supabaseKey!);

// Direct Connect using Postgres
const { supabaseDirectUrl } = config.dbConfig;
export const sql = postgres(supabaseDirectUrl!);
// API Connect
const { supabaseUrl, supabaseKey } = config.dbConfig;
export const supabase = createClient(supabaseUrl!, supabaseKey!);

// Direct Connect using Postgres
const { supabaseDirectUrl } = config.dbConfig;
export const sql = postgres(supabaseDirectUrl!);


Now I can use both functionalities anywhere in my app. Incase I want to raw dog SQL, I can just use sql
select * from users
select * from users
; else i can use
await supabase.from("users").select('*')
await supabase.from("users").select('*')
.

I did this because i wasn't able to use complex joins using the api connect. So i can use any one of them when needed.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Error in createClient
SupabaseSSupabase / help-and-questions
4y ago
Connect to Postgres in a long-running node server
SupabaseSSupabase / help-and-questions
4mo ago
Supabase / Postgres question
SupabaseSSupabase / help-and-questions
14mo ago
Zapier + Supabase Postgres
SupabaseSSupabase / help-and-questions
4y ago