@Isaac McFadyen | YYZ01 - your jave library is pretty cool thanks
@Isaac McFadyen | YYZ01 - your jave library is pretty cool thanks
.set() method if one takes only 1 write..upsert() [cause]: Error: FOREIGN KEY constraint failedblobId, but shouldnt last_insert_rowid() return the id of the latest inserted blob ? as in the first batch statement?


UPDATE ... RETURNING *?The request is malformed: failed to decode idhttps://api.cloudflare.com/client/v4/accounts/{account_id}/d1/database/{db_id}/querydb_id is right?body from the looks of itINSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...)
ON CONFLICT (constraint_column)
DO UPDATE SET column1 = value1, column2 = value2, ...;INSERT OR REPLACE INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);await this.db.batch([
this.db.insert(blobs).values({ hash: blobHash }),
this.db
.insert(assets)
.values({ projectId, blobId: sql`last_insert_rowid()` })
.returning({ assetId: assets.id }),
]);CREATE TABLE `assets` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`ref_count` integer DEFAULT 1 NOT NULL,
`blob_id` integer NOT NULL,
`user_id` integer NOT NULL,
`created_at` integer DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`blob_id`) REFERENCES `blobs`(`id`) ON UPDATE cascade ON DELETE restrict,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE cascade ON DELETE restrict
);
CREATE TABLE `blobs` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`hash` text NOT NULL
);const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer {api_token}'
},
body: `{"sql": ${insertStatement}`
}