Updated replica handling. Fixed types.
Some checks are pending
Create docker images / Build, push, and deploy (push) Waiting to run
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run

This commit is contained in:
Mike Cao 2025-10-03 01:20:48 -07:00
parent b36cd48b4a
commit f70f98fed0
9 changed files with 83 additions and 168 deletions

View file

@ -187,9 +187,7 @@ async function rawQuery(sql: string, data: Record<string, any>, name?: string):
return `$${params.length}${type ?? ''}`;
});
return process.env.DATABASE_REPLICA_URL
? await client.$replica().$queryRawUnsafe(query, ...params)
: await client.$queryRawUnsafe(query, ...params);
return client.$queryRawUnsafe(query, ...params);
}
async function pagedQuery<T>(model: string, criteria: T, filters?: QueryFilters) {
@ -283,6 +281,7 @@ function getClient() {
url: process.env.DATABASE_URL,
prismaClient: PrismaClient,
logQuery: !!process.env.LOG_QUERY,
replicaUrl: process.env.DATABASE_REPLICA_URL,
});
if (process.env.NODE_ENV !== 'production') {
@ -292,7 +291,7 @@ function getClient() {
return prisma.client;
}
const client = globalThis[PRISMA] || getClient();
const client: PrismaClient = globalThis[PRISMA] || getClient();
export default {
client,