refactor(db): typed query helpers, shared test FormData helper
CI / check (push) Successful in 4m10s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 2m4s

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:
openhands committed 2026-09-17 21:02:57 +02:00
1 parent 2e25b39364
commit 8638e81444
116 files changed
+866 -897

No files matched your search

+8 -8
View File
@@ -2,7 +2,7 @@
import { sql } from "drizzle-orm";
import { z } from "zod";
import { namedTableView, tableViewPath } from "@/lib/admin/table-view-state";
import { db } from "@/lib/db";
import { db, queryRows, rowsFrom } from "@/lib/db";
import { PERMS } from "@/lib/permission-slugs";
import { adminAction } from "@/lib/safe-action";
@@ -25,11 +25,10 @@ export const listTableViews = adminAction(
schema: z.object({ path: tableViewPath }),
},
async ({ session, data }) => {
const [rows] = await db.execute(
sql`SELECT name, state FROM website_admin_table_views WHERE user_id = ${Number(session.user.id)} AND path = ${data.path} ORDER BY name LIMIT 20`,
);
const views = (
rows as unknown as { name: string; state: string }[]
await queryRows<{ name: string; state: string }>(
sql`SELECT name, state FROM website_admin_table_views WHERE user_id = ${Number(session.user.id)} AND path = ${data.path} ORDER BY name LIMIT 20`,
)
).flatMap((row) => {
try {
const parsed = namedTableView.safeParse({
@@ -58,10 +57,11 @@ export const saveTableView = adminAction(
await tx.execute(
sql`SELECT id FROM users WHERE id = ${userId} FOR UPDATE`,
);
const [rows] = await tx.execute(
sql`SELECT name FROM website_admin_table_views WHERE user_id = ${userId} AND path = ${data.path}`,
const names = rowsFrom<{ name: string }>(
await tx.execute(
sql`SELECT name FROM website_admin_table_views WHERE user_id = ${userId} AND path = ${data.path}`,
),
);
const names = rows as unknown as { name: string }[];
if (
names.length >= 20 &&
!names.some(