fix: standardize dbExec/dbQuery param passing as arrays
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
ffea415613
commit
cc7a6842ed
@ -157,12 +157,12 @@ export function getPrisma(dbUrl: string): PrismaClient {
|
|||||||
return prisma;
|
return prisma;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dbExec(dbUrl: string, sql: string, ...params: any[]): Promise<void> {
|
export async function dbExec(dbUrl: string, sql: string, params: any[] = []): Promise<void> {
|
||||||
const p = getPrisma(dbUrl);
|
const p = getPrisma(dbUrl);
|
||||||
await p.$executeRawUnsafe(sql, ...params);
|
await p.$executeRawUnsafe(sql, ...params);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dbQuery<T = any>(dbUrl: string, sql: string, ...params: any[]): Promise<T[]> {
|
export async function dbQuery<T = any>(dbUrl: string, sql: string, params: any[] = []): Promise<T[]> {
|
||||||
const p = getPrisma(dbUrl);
|
const p = getPrisma(dbUrl);
|
||||||
return (await p.$queryRawUnsafe(sql, ...params)) as T[];
|
return (await p.$queryRawUnsafe(sql, ...params)) as T[];
|
||||||
}
|
}
|
||||||
@ -173,19 +173,19 @@ export async function dbClose(): Promise<void> {
|
|||||||
|
|
||||||
export async function setupFixtures(dbUrl: string, userId: string, kbId: string, kiId: string, sessionId: string): Promise<void> {
|
export async function setupFixtures(dbUrl: string, userId: string, kbId: string, kiId: string, sessionId: string): Promise<void> {
|
||||||
await dbExec(dbUrl, `INSERT IGNORE INTO User (id, email, nickname, role, status) VALUES (?, ?, ?, ?, ?)`,
|
await dbExec(dbUrl, `INSERT IGNORE INTO User (id, email, nickname, role, status) VALUES (?, ?, ?, ?, ?)`,
|
||||||
userId, `test-${Date.now()}@zhixi.app`, 'Integration Test', 'USER', 'active');
|
[userId, `test-${Date.now()}@zhixi.app`, 'Integration Test', 'USER', 'active']);
|
||||||
await dbExec(dbUrl, `INSERT IGNORE INTO KnowledgeBase (id, userId, title) VALUES (?, ?, ?)`,
|
await dbExec(dbUrl, `INSERT IGNORE INTO KnowledgeBase (id, userId, title) VALUES (?, ?, ?)`,
|
||||||
kbId, userId, 'Test KB');
|
[kbId, userId, 'Test KB']);
|
||||||
await dbExec(dbUrl, `INSERT IGNORE INTO KnowledgeItem (id, userId, knowledgeBaseId, itemType, title, content, status) VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
await dbExec(dbUrl, `INSERT IGNORE INTO KnowledgeItem (id, userId, knowledgeBaseId, itemType, title, content, status) VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||||
kiId, userId, kbId, 'concept', 'Test Item', 'Test content.', 'active');
|
[kiId, userId, kbId, 'concept', 'Test Item', 'Test content.', 'active']);
|
||||||
await dbExec(dbUrl, `INSERT IGNORE INTO LearningSession (id, userId, knowledgeBaseId, knowledgeItemId, mode, status, startedAt) VALUES (?, ?, ?, ?, ?, ?, NOW())`,
|
await dbExec(dbUrl, `INSERT IGNORE INTO LearningSession (id, userId, knowledgeBaseId, knowledgeItemId, mode, status, startedAt) VALUES (?, ?, ?, ?, ?, ?, NOW())`,
|
||||||
sessionId, userId, kbId, kiId, 'active_recall', 'active');
|
[sessionId, userId, kbId, kiId, 'active_recall', 'active']);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cleanupFixtures(dbUrl: string, userId: string): Promise<void> {
|
export async function cleanupFixtures(dbUrl: string, userId: string): Promise<void> {
|
||||||
const tables = ['ReviewCard', 'FocusItem', 'AiAnalysisResult', 'AiAnalysisJob', 'LearningSession', 'KnowledgeItem', 'KnowledgeBase'];
|
const tables = ['ReviewCard', 'FocusItem', 'AiAnalysisResult', 'AiAnalysisJob', 'LearningSession', 'KnowledgeItem', 'KnowledgeBase'];
|
||||||
for (const t of tables) {
|
for (const t of tables) {
|
||||||
await dbExec(dbUrl, `DELETE FROM \`${t}\` WHERE userId = ?`, userId).catch(() => {});
|
await dbExec(dbUrl, `DELETE FROM \`${t}\` WHERE userId = ?`, [userId]).catch(() => {});
|
||||||
}
|
}
|
||||||
await dbExec(dbUrl, `DELETE FROM User WHERE id = ?`, userId).catch(() => {});
|
await dbExec(dbUrl, `DELETE FROM User WHERE id = ?`, [userId]).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user