From 11dc935f41de5bd533b7edf13663536a856a1366 Mon Sep 17 00:00:00 2001 From: Jon Breen Date: Sun, 18 Feb 2024 16:04:00 +0000 Subject: [PATCH] Custom In clause --- src/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7528017..9b9a953 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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))