Skip to content

Commit

Permalink
api/store: Fix updateStatus query
Browse files Browse the repository at this point in the history
Can't parametrize table name
  • Loading branch information
victorges committed Apr 23, 2024
1 parent 39e9b14 commit feb1bb0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/api/src/store/webhook-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ export default class WebhookTable extends Table<DBWebhook> {
}

async updateStatus(id: string, status: DBWebhook["status"]) {
const statusStr = JSON.stringify(status);
const res = await this.db.query(
sql`UPDATE ${
this.name
} SET data = jsonb_set(data, '{status}', case when data->'status' is null then '{}' else data->'status' end || '${JSON.stringify(
status
)}') WHERE id = '${id}'`
sql``
.append(`UPDATE ${this.name} `) // table name can't be parameterized, append a raw string
.append(
sql`SET data = jsonb_set(data, '{status}', case when data->'status' is null then '{}' else data->'status' end || '${statusStr}') `
)
.append(sql`WHERE id = '${id}'`)
);

if (res.rowCount < 1) {
Expand Down

0 comments on commit feb1bb0

Please sign in to comment.