From edfeec900dd23d2a6a27bef41815ea8e69829e8f Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 31 Mar 2026 14:25:47 -0700 Subject: [PATCH] Define db type --- server/db/pg/driver.ts | 6 +++--- server/db/sqlite/driver.ts | 3 ++- server/routers/gerbil/receiveBandwidth.ts | 8 ++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/server/db/pg/driver.ts b/server/db/pg/driver.ts index 9366e32e1..86a0c0352 100644 --- a/server/db/pg/driver.ts +++ b/server/db/pg/driver.ts @@ -60,8 +60,7 @@ function createDb() { }) ); } else { - const maxReplicaConnections = - poolConfig?.max_replica_connections || 20; + const maxReplicaConnections = poolConfig?.max_replica_connections || 20; for (const conn of replicaConnections) { const replicaPool = createPool( conn.connection_string, @@ -91,4 +90,5 @@ export default db; export const primaryDb = db.$primary; export type Transaction = Parameters< Parameters<(typeof db)["transaction"]>[0] ->[0]; \ No newline at end of file +>[0]; +export const DB_TYPE: "pg" | "sqlite" = "pg"; diff --git a/server/db/sqlite/driver.ts b/server/db/sqlite/driver.ts index 9cbc8d7be..832ff16f9 100644 --- a/server/db/sqlite/driver.ts +++ b/server/db/sqlite/driver.ts @@ -23,7 +23,8 @@ export default db; export const primaryDb = db; export type Transaction = Parameters< Parameters<(typeof db)["transaction"]>[0] ->[0]; + >[0]; +export const DB_TYPE: "pg" | "sqlite" = "sqlite"; function checkFileExists(filePath: string): boolean { try { diff --git a/server/routers/gerbil/receiveBandwidth.ts b/server/routers/gerbil/receiveBandwidth.ts index 787b7b702..b4cce8c4e 100644 --- a/server/routers/gerbil/receiveBandwidth.ts +++ b/server/routers/gerbil/receiveBandwidth.ts @@ -1,6 +1,6 @@ import { Request, Response, NextFunction } from "express"; import { sql } from "drizzle-orm"; -import { db } from "@server/db"; +import { db, DB_TYPE } from "@server/db"; import logger from "@server/logger"; import createHttpError from "http-errors"; import HttpCode from "@server/types/HttpCode"; @@ -96,12 +96,8 @@ async function dbQueryRows>( return (await anyDb.all(query)) as T[]; } -/** - * Returns true when the active database driver is SQLite (better-sqlite3). - * Used to select the appropriate bulk-update strategy. - */ function isSQLite(): boolean { - return typeof (db as any).execute !== "function"; + return DB_TYPE == "sqlite"; } /**