fix: D1 bind params must be spread, not chained (refs #5)
CI / test (push) Has been cancelled
CI / test (push) Has been cancelled
This commit is contained in:
@@ -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') {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user