I guess I would have to create a function for each one and then pass in the DB instance as a param?
I guess I would have to create a function for each one and then pass in the DB instance as a param? But then are they being cached properly?
A prepared SQL statement must contain only one statement . It's a useful kind of query that avoid one round trip.D1_ERROR: no such table: main.lists when a trigger is ran. Might be something to do with main., but I don't know where it's coming from. Here is the trigger declaration:A prepared SQL statement must contain only one statement.RETURNING * to get the id from an insert/updatereturning * to the end of an update/insert to be able to use it in a subsequent query, by itself it's not valid
To execute a transaction, please use the state.storage.transaction() API instead of the SQL BEGIN TRANSACTION or SAVEPOINT statements. The JavaScript API is safer because it will automatically roll back on exceptions, and because it interacts correctly with Durable Objects' automatic atomic write coalescing.BEGIN TRANSACTION;
INSERT INTO user (email, name) VALUES ("my@email.com", "name");
SELECT last_insert_rowid() INTO @lastUserId;
INSERT INTO oauth (provider, user_id) VALUES ("google", @lastUserId);
COMMIT;
SELECT @lastUserIDA prepared SQL statement must contain only one statement❯ wrangler d1 execute database --file=data.sql 🌀 Mapping SQL input into an array of statements
🌀 Parsing 180 statements
🌀 Executing on database (...):
✘ [ERROR] A request to the Cloudflare API (/accounts/.../d1/database/.../query) failed.
not authorized [code: 7500]sqlite3 f025eb6fc80fddcfe00b28c2b12457379be412d5d8d8fd306b42c59a9536d18c.sqlite .dump > data.sqlD1_ERROR: no such table: main.listsA prepared SQL statement must contain only one statement.RETURNING *returning *CREATE TRIGGER limit_user_lists
BEFORE INSERT ON list_member
FOR EACH ROW
BEGIN
SELECT (CASE
WHEN (SELECT COUNT(*)
FROM list_member lm
INNER JOIN lists l ON lm.listId = l.id
WHERE lm.userId = NEW.userId AND l.deteled = false) >= 20
THEN
RAISE(ABORT, 'User has reached the limit of 20 lists')
END);
END; const newUserId = await DB.prepare(
`
INSERT INTO user (email, name) VALUES (?,?);
SELECT last_insert_rowid() INTO @lastID;
INSERT INTO oauth_account (provider_id, provider_user_id, user_id) VALUES ("google", ?, @lastID);
SELECT @lastID;`,
)
.bind(email, name, provider_user_id)
.run();const newUser = await DB.prepare(
`INSERT INTO user (email, name) VALUES (?,?);
RETURNING *;
INSERT INTO oauth_account (provider_id, provider_user_id, user_id) VALUES ('google', ?, @lastID)`
)
.bind(email, name, provider_user_id)
.run();