Do I need to cache `createClient`?

I use turso on the edge (CF Workers). I see a lot of implementations do something like this:
let cached_db = null
export const useDb = () => {
if (!cached_db){
const client = createClient({ url, authToken })
cached_db = drizzle(client, { schema:schema_file })
}
return cached_db
}
// And then use it like:
const db = useDb()
let cached_db = null
export const useDb = () => {
if (!cached_db){
const client = createClient({ url, authToken })
cached_db = drizzle(client, { schema:schema_file })
}
return cached_db
}
// And then use it like:
const db = useDb()
Is that the right approach? Or can I simply do:
const client = createClient({ url, authToken })
export const db = drizzle(client, { schema:schema_file })
const client = createClient({ url, authToken })
export const db = drizzle(client, { schema:schema_file })
Like can I call createClient() hundreds of times without issues or I should actually cache it?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server