MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / getReplicaClient

Function getReplicaClient

apps/webapp/app/db.server.ts:137–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

135}
136
137function getReplicaClient() {
138 if (!env.DATABASE_READ_REPLICA_URL) {
139 console.log(`🔌 No database replica, using the regular client`);
140 return;
141 }
142
143 const replicaUrl = extendQueryParams(env.DATABASE_READ_REPLICA_URL, {
144 connection_limit: env.DATABASE_CONNECTION_LIMIT.toString(),
145 pool_timeout: env.DATABASE_POOL_TIMEOUT.toString(),
146 });
147
148 console.log(`🔌 setting up read replica connection to ${redactUrlSecrets(replicaUrl)}`);
149
150 const replicaClient = new PrismaClient({
151 datasources: {
152 db: {
153 url: replicaUrl.href,
154 },
155 },
156 log: [
157 {
158 emit: "stdout",
159 level: "error",
160 },
161 {
162 emit: "stdout",
163 level: "info",
164 },
165 {
166 emit: "stdout",
167 level: "warn",
168 },
169 ],
170 });
171
172 // connect eagerly
173 replicaClient.$connect();
174
175 console.log(`🔌 read replica connected`);
176
177 return replicaClient;
178}
179
180function extendQueryParams(hrefOrUrl: string | URL, queryParams: Record<string, string>) {
181 const url = new URL(hrefOrUrl);

Callers 1

db.server.tsFile · 0.85

Calls 4

extendQueryParamsFunction · 0.85
redactUrlSecretsFunction · 0.85
toStringMethod · 0.80
logMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…