fix: D1 bind params must be spread, not chained (refs #5)
CI / test (push) Has been cancelled

This commit is contained in:
2026-04-18 08:12:33 +00:00
parent b533094792
commit 25591e2c21
2 changed files with 14 additions and 16 deletions
+11 -4
View File
@@ -45,10 +45,17 @@ export class PulseTick implements DurableObject {
}
if (request.method === 'GET' && url.pathname === '/status') {
const status = await this.getStatus();
return new Response(JSON.stringify(status), {
headers: { 'Content-Type': 'application/json' }
});
try {
const status = await this.getStatus();
return new Response(JSON.stringify(status), {
headers: { 'Content-Type': 'application/json' }
});
} catch (e: any) {
return new Response(JSON.stringify({ error: e.message, stack: e.stack }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
}
if (request.method === 'POST' && url.pathname === '/start') {
+3 -12
View File
@@ -137,10 +137,7 @@ export class D1PulseStore implements PulseStore {
}
const sql = `SELECT * FROM events WHERE ${conditions.join(' AND ')} ORDER BY occurred_at DESC, id DESC LIMIT 1`;
let stmt = this.db.prepare(sql);
for (const param of params) {
stmt = stmt.bind(param);
}
const stmt = this.db.prepare(sql).bind(...params);
const row = await stmt.first<any>();
return row ? this.rowToEventRecord(row) : null;
@@ -186,10 +183,7 @@ export class D1PulseStore implements PulseStore {
params.push(opts.limit);
}
let stmt = this.db.prepare(sql);
for (const param of params) {
stmt = stmt.bind(param);
}
const stmt = this.db.prepare(sql).bind(...params);
const { results } = await stmt.all<any>();
return results.map(row => this.rowToEventRecord(row));
@@ -220,10 +214,7 @@ export class D1PulseStore implements PulseStore {
}
const sql = `SELECT * FROM events WHERE ${conditions.join(' AND ')} ORDER BY id ASC`;
let stmt = this.db.prepare(sql);
for (const param of params) {
stmt = stmt.bind(param);
}
const stmt = this.db.prepare(sql).bind(...params);
const { results } = await stmt.all<any>();
return results.map(row => this.rowToEventRecord(row));