Is global client recommended for local development

Prisma recommends that you create a global client for local development to avoid creating a ton of clients locally if you are working with a serverless application. The recommended code looks something like this:
declare global {
// eslint-disable-next-line vars-on-top, no-var
var localDrizzle: ReturnType<typeof drizzleClient>;
}

if (typeof window === 'undefined') {
if (process.env.NODE_ENV === 'production') {
return drizzle(sql, { schema });
}

if (!global.localDrizzle) {
global.localDrizzle = drizzle(sql, { schema });
}
return global.localDrizzle;
}
declare global {
// eslint-disable-next-line vars-on-top, no-var
var localDrizzle: ReturnType<typeof drizzleClient>;
}

if (typeof window === 'undefined') {
if (process.env.NODE_ENV === 'production') {
return drizzle(sql, { schema });
}

if (!global.localDrizzle) {
global.localDrizzle = drizzle(sql, { schema });
}
return global.localDrizzle;
}
Is the same recommended for drizzle?
1 Reply
Angelelz
Angelelz11mo ago
Yes
Want results from more Discord servers?
Add your server