Skip to content

Commit

Permalink
Custom In clause
Browse files Browse the repository at this point in the history
  • Loading branch information
cultpodcasts committed Feb 18, 2024
1 parent 5f310c4 commit 11dc935
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,17 @@ export default {
.prepare("SELECT id FROM urls WHERE state=0");
let result = await submissionIds.all();
if (result.success) {
const inClause = result.results
.map((urlId) => {
if (!Number.isInteger(urlId.id)) { throw Error("invalid id, expected an integer"); }
return urlId.id;
})
.join(',');
let query = "UPDATE urls SET state=1 WHERE id IN ($urlIds)"
query = query.replace('$urlIds', inClause);
console.log(query);
let raiseState = await env.DB
.prepare("UPDATE urls SET state=1 WHERE id IN (?)")
.bind(result.results)
.prepare(query)
.run();
if (raiseState.success) {
return new Response(JSON.stringify(result.results))
Expand Down

0 comments on commit 11dc935

Please sign in to comment.