refactor(db): typed query helpers, shared test FormData helper
Replace raw db.execute tuple casts with queryRows/rowsFrom/execResult/ affectedRows helpers from lib/db, drop redundant mysql2 casts on typed query builders, and centralize per-test fakeForm into test/fake-form. Update db mocks in tests so helpers resolve against mocked execute.
This commit is contained in:
1 parent
2e25b39364
commit
8638e81444
116 files changed
+866
-897
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { existsSync, promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db, ItemsBase } from "@/lib/db";
|
||||
import { db, ItemsBase, queryRows } from "@/lib/db";
|
||||
import { autoDetectInteraction } from "@/lib/furni/auto-interaction";
|
||||
import { logServerError } from "@/lib/server-log";
|
||||
import { getFurniAssetWriteTargets } from "@/lib/services/furni-asset-dirs";
|
||||
@@ -105,9 +105,9 @@ async function allocateItemsBaseId<T>(
|
||||
itemsBaseNextId === null ||
|
||||
Date.now() - itemsBaseIdLastUsed > ITEMS_BASE_ID_REFRESH_MS
|
||||
) {
|
||||
const [idRows] = (await db.execute(sql`
|
||||
const idRows = await queryRows<{ next: number }>(sql`
|
||||
SELECT COALESCE(MAX(id), 0) + 1 AS next FROM items_base
|
||||
`)) as unknown as [Array<{ next: number }>, unknown];
|
||||
`);
|
||||
itemsBaseNextId = Number(idRows[0]?.next ?? 1);
|
||||
}
|
||||
} finally {
|
||||
@@ -410,9 +410,9 @@ export async function uploadSingleFurni(params: {
|
||||
try {
|
||||
// Skip when the item already has a catalog row — re-uploads must never
|
||||
// create a second row for the same item_ids.
|
||||
const [existingCatalog] = (await db.execute(sql`
|
||||
const existingCatalog = await queryRows<{ id: number }>(sql`
|
||||
SELECT id FROM catalog_items WHERE item_ids = ${String(newId)} LIMIT 1
|
||||
`)) as unknown as [Array<{ id: number }>, unknown];
|
||||
`);
|
||||
if (existingCatalog.length > 0) {
|
||||
catalogItemId = existingCatalog[0].id;
|
||||
warnings.push(
|
||||
|
||||
Reference in new issue
Block a user