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, execResult, ItemsBase, queryRows } from "@/lib/db";
|
||||
import {
|
||||
getGamedataRoot,
|
||||
getNitroFilesRoot,
|
||||
@@ -698,14 +698,14 @@ export interface CatalogOfferRebuildResult {
|
||||
*/
|
||||
export async function rebuildCatalogOfferIds(): Promise<CatalogOfferRebuildResult> {
|
||||
return withFurniDataLock(async () => {
|
||||
const [countRows] = (await db.execute(
|
||||
const countRows = await queryRows<{ total: number }>(
|
||||
sql`SELECT COUNT(*) AS total FROM catalog_items`,
|
||||
)) as unknown as [Array<{ total: number }>, unknown];
|
||||
);
|
||||
const checked = Number(countRows?.[0]?.total ?? 0);
|
||||
|
||||
const [result] = (await db.execute(sql`
|
||||
const result = await execResult(sql`
|
||||
UPDATE catalog_items SET offer_id = id WHERE offer_id <> id
|
||||
`)) as unknown as [Record<string, unknown>, unknown];
|
||||
`);
|
||||
|
||||
return { checked, fixed: Number(result.affectedRows ?? 0) };
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user