Skip to content

Commit ca807d1

Browse files
committed
Use proper SqlStorage object for executions
1 parent 975fd0d commit ca807d1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/import/json.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface JsonData {
1111
}
1212

1313
export async function importTableFromJsonRoute(
14+
sql: SqlStorage,
1415
operationQueue: any,
1516
ctx: any,
1617
processingOperation: { value: boolean },
@@ -58,11 +59,11 @@ export async function importTableFromJsonRoute(
5859
const values = Object.values(mappedRecord);
5960
const placeholders = values.map(() => '?').join(', ');
6061

61-
const sql = `INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${placeholders})`;
62+
const statement = `INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${placeholders})`;
6263

6364
try {
6465
await enqueueOperation(
65-
[{ sql, params: values }],
66+
[{ sql: statement, params: values }],
6667
false,
6768
false,
6869
operationQueue,
@@ -71,8 +72,8 @@ export async function importTableFromJsonRoute(
7172
successCount++;
7273
} catch (error: any) {
7374
failedStatements.push({
74-
statement: sql,
75-
error: error.message || 'Unknown error'
75+
statement: statement,
76+
error: error || 'Unknown error'
7677
});
7778
}
7879
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class DatabaseDurableObject extends DurableObject {
150150
if (!tableName) {
151151
return createResponse(undefined, 'Table name is required', 400);
152152
}
153-
return importTableFromJsonRoute(this.operationQueue, this.ctx, this.processingOperation, tableName, request);
153+
return importTableFromJsonRoute(this.sql, this.operationQueue, this.ctx, this.processingOperation, tableName, request);
154154
} else {
155155
return createResponse(undefined, 'Unknown operation', 400);
156156
}

0 commit comments

Comments
 (0)