is following a valid SQL for execution by Cloudflare D1 .. thanks .. Reason (shared by ChatGPT) : A

is following a valid SQL for execution by Cloudflare D1 .. thanks ..

Reason (shared by ChatGPT) : As of July 2025, there's no evidence that changes() is supported in D1. Its omission in docs combined with reported limitations strongly suggests it’s not available.

Worker Code Snippet with SQL execution planned :
// AIM : "to execute stmtUpdate statement ONLY if insertRes statement is success, without any JS stament in between D1 calls"
const stmts = await env.DB.batch([
env.DB.prepare(INSERT INTO users (sid) VALUES (?)).bind(sid),
env.DB.prepare( UPDATE users SET number_of_books = number_of_books + 1 WHERE sid = ? AND changes() = 1 ).bind(sid)
]);

SQL File : (for reference)

CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sid TEXT UNIQUE,
number_of_books INTEGER NOT NULL DEFAULT 0
);
Was this page helpful?