Create a Drizzle Instance on request, if that is what you mean?
Create a Drizzle Instance on request, if that is what you mean?
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 @lastUserID🌀 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]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();