Skip to content

Add basic support for sqlite-backed durable objects #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

@zebp @danlapid fyi

Copy link

@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),

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
Collaborator

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),
)
}

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
Collaborator

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
Collaborator

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
Collaborator

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
Collaborator

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

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
5 participants