not to bikeshed your ORM but i think others call that `.upsert()`
not to bikeshed your ORM but i think others call that
.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 itAuthorization header also doesn't seem to be actually interpolating the api_token variableX-Auth-Key but i get an error that it doesn't exist in the requestaccount_id and db_id? They're not sensitive.4f6d1970bc967b2c2a90b643bbb5ac940e35121-f3cc-4e24-b5c1-4d758860a69dconsole.log it?https://api.cloudflare.com/client/v4/accounts/4f6d1970bc967b2c2a90b643bbb5ac94/d1/database/0e35121-f3cc-4e24-b5c1-4d758860a69d/queryoptions then you see Authorization: Bearer ...?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 }),
]);UPDATE ... RETURNING *The request is malformed: failed to decode idhttps://api.cloudflare.com/client/v4/accounts/{account_id}/d1/database/{db_id}/queryconst insertStatement = `INSERT INTO table (column1, column2) VALUES ('value1', 'value2');`;const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer {api_token}'
},
body: `{"sql": ${insertStatement}`
}db_iddb_idAuthorizationapi_tokenX-Auth-Keyaccount_id4f6d1970bc967b2c2a90b643bbb5ac940e35121-f3cc-4e24-b5c1-4d758860a69dhttps://api.cloudflare.com/client/v4/accounts/4f6d1970bc967b2c2a90b643bbb5ac94/d1/database/0e35121-f3cc-4e24-b5c1-4d758860a69d/queryoptionsAuthorization: Bearer ...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
);