Skip to content

Commit 89dfc53

Browse files
syed-reza98Copilot
andauthored
Update src/lib/prisma-utils.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent df84234 commit 89dfc53

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/lib/prisma-utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
* Detects the database provider from DATABASE_URL
77
* @returns 'postgresql' | 'sqlite' | 'unknown'
88
*/
9+
let cachedProvider: 'postgresql' | 'sqlite' | 'unknown' | null = null;
10+
911
export function getDatabaseProvider(): 'postgresql' | 'sqlite' | 'unknown' {
12+
if (cachedProvider !== null) {
13+
return cachedProvider;
14+
}
15+
1016
const databaseUrl = process.env.DATABASE_URL || '';
1117

1218
if (databaseUrl.startsWith('postgresql://') || databaseUrl.startsWith('postgres://')) {
13-
return 'postgresql';
14-
}
15-
16-
if (databaseUrl.startsWith('file:') || databaseUrl.includes('sqlite')) {
17-
return 'sqlite';
19+
cachedProvider = 'postgresql';
20+
} else if (databaseUrl.startsWith('file:') || databaseUrl.includes('sqlite')) {
21+
cachedProvider = 'sqlite';
22+
} else {
23+
cachedProvider = 'unknown';
1824
}
1925

20-
return 'unknown';
26+
return cachedProvider;
2127
}
2228

2329
/**

0 commit comments

Comments
 (0)