Skip to content

Conversation

@connyay
Copy link
Contributor

@connyay connyay commented May 14, 2025

Fixes #645

@connyay
Copy link
Contributor Author

connyay commented May 14, 2025

alt to #723 with some additional bindgen methods, a test, and a sandbox example.

This PR uses jsvalue pretty liberally and omits SqlStorageValue. Happy to make a change if needed, but types are already wonky in sqlite and the rust/wasm layers make it even more confusing. Would love from someone from cloudflare to weigh in there. Ideally could skip things like https://github.com/cloudflare/workers-rs/pull/723/files#r2045394966 if we are just ysing jsvalues? 🤷‍♂️

@connyay
Copy link
Contributor Author

connyay commented Jun 17, 2025

Ended up adding SqlStorageValue after attempting to use my fork. Definitely improves ergonomics.

guybedford
guybedford previously approved these changes Jun 17, 2025
Copy link
Collaborator

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

This is great, thank you.

connyay and others added 4 commits June 17, 2025 13:42
* improve ergonomics with bindings: Vec<JsValue> -> bindings: impl Into<Option<Vec<SqlStorageValue>>>
* add SqlStorageValue types
* enable sqlite.spec.ts
Copy link
Collaborator

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

Thanks so much for following up on this. Marking the TODOs for experimental features makes sense to me. I'd be happy to keep working this one through if we can get it in for the coming release.

@connyay connyay requested a review from guybedford June 17, 2025 23:36
@connyay
Copy link
Contributor Author

connyay commented Jun 17, 2025

sry. I was only iterating on npm run test 👼

guybedford
guybedford previously approved these changes Jun 18, 2025
Copy link
Collaborator

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks for getting the good test coverage in as well.

The test coverage looks really solid as well. Is it possible to get a test case in where the next() iterator doesn't type match through the serde type with the expected data to test the error on that?

Apart from that just needs a last cargo fmt as well it seems, then we're just about there I think!

Comment on lines 22 to 23
/// 32-bit signed integer (safe for JavaScript Number conversion)
Integer(i32),
Copy link
Collaborator

@guybedford guybedford Jun 18, 2025

Choose a reason for hiding this comment

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

Thinking about this one again, I think it would make more sense to use i64 and then have a guard when setting to determine that it is between Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER for JS. That gets us over 6 byte integers at least, which would be a big improvement over 4 byte integers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hobbled something together. feels a bit messy/dangerous

+1 on cloudflare/workerd#4195

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I see what you mean about this. I'd quite like to (a) know what the upgrade path to bigint would look like and be sure this isn't now inhibiting that and (b) investigate the bigint approach more.

I guess for the bigint upgrade we would want Integer(i32) along with BigInteger(i64)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or, would we just have Integer(i64) where the JS API semantics are that:

  • Conversion to JS will use BigInt when outside i32 range
  • Conversion to JS will always use BigInt if that's supported safely
  • Conversion from JS would always support either

I guess thinking this through some more the above seems absolutely fine to me from an interop perspective without needing any other special handling, so that Integer(i64) from the start is the correct end design, since it would be more painful on the bigint upgrade path to have an opt-in variant based on range.

@guybedford
Copy link
Collaborator

Thanks again for your work on this!

@guybedford guybedford merged commit 0c0c2eb into cloudflare:main Jun 18, 2025
3 checks passed
@connyay connyay deleted the sqlite branch June 18, 2025 19:51
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

2 participants