Skip to content

Conversation

@maxbrunsfeld
Copy link

Fixes #645

Hi, we want to use sqlite-backed durable objects using Rust, so we added some bindings to the Sql Storage API. Let us know if there are changes you'd like to see. Thanks.

@PeterMHammond
Copy link

This looks fantastic!!

@maxbrunsfeld maxbrunsfeld force-pushed the sqlite-durable-objects branch from 1a9b519 to e0a401e Compare April 14, 2025 23:12
@PeterMHammond
Copy link

I say wrangler 4.10.0 (update available 4.11.0) and thought WOW it's been approved - awesome.....but then came to see this is still sitting unreviewed. 👎

@spigaz
Copy link
Contributor

spigaz commented Apr 15, 2025

You might want to try to get in touch with one of the developers that get their PRs accepted to see if you can get merged.

@lukevalenta
Copy link
Contributor

@zebp @danlapid fyi

Copy link
Contributor

@lukevalenta lukevalenta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice addition to this PR would be some tests/example code in worker-sandbox, e.g., c4107bf. And an update to the README at https://github.com/cloudflare/workers-rs?tab=readme-ov-file#durable-objects to use new_sqlite_classes, etc.

(I'm not a maintainer on this repo, but that should help to get this merged quickly.)

pub enum SqlStorageValue {
Null,
Boolean(bool),
Integer(i32),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQLite integers can be up to 8 bytes (https://sqlite.org/datatype3.html). Any reason not to use i64 here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't losslessly convert to number from an i64 and the DO sql api doesn't seem to support using BigInt for values above Number.MAX_SAFE_INTEGER. I'll ask the DO team for clarification to see if we can support this

row.and_then(|row| serde_wasm_bindgen::from_value(row).map_err(JsValue::from))
.map_err(Error::from),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to add support for toArray and raw as well? https://developers.cloudflare.com/durable-objects/api/storage-api/#returns

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
pub type DurableObjectSqlStorage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should name this SqlStorage

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few more methods for this class that we should implement: https://workers-types.pages.dev/#SqlStorage

}

#[wasm_bindgen]
extern "C" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more methods that we should implement: https://workers-types.pages.dev/#SqlStorageCursor

pub enum SqlStorageValue {
Null,
Boolean(bool),
Integer(i32),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't losslessly convert to number from an i64 and the DO sql api doesn't seem to support using BigInt for values above Number.MAX_SAFE_INTEGER. I'll ask the DO team for clarification to see if we can support this

@connyay
Copy link
Contributor

connyay commented Jun 17, 2025

I'd love to get this across the line. I've made some improvements on my fork. I have been using it successfully.

#727

@guybedford
Copy link
Collaborator

Thanks @maxbrunsfeld for getting this one started. This has now been landed in #727.

@guybedford guybedford closed this Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce SQLite API for Durable Objects

7 participants