Skip to content
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

feat: cloudflare-sqlite for durable objects #787

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

Conversation

mattzcarey
Copy link

Cloudflare durable objects have a slightly different sqlite api.

Tests are not passing cause I am getting some weird esm errors, but this works for me in a durable object.

Have a great weekend,
Matt

@jacoblee93
Copy link
Collaborator

Very nice! A bit bogged down but will look next week after the holiday.

CC @benjamincburns

@benjamincburns
Copy link
Contributor

@mattzcarey great to see this come through! Can you please add this to the tests in the checkpoint-validation suite as well? That test suite will make sure that it conforms to all of the logical requirements for checkpointers.

@mattzcarey
Copy link
Author

Hey @benjamincburns, not sure how I can do that since the sqlite api doesnt really exist outside of durable objects. I'll see if I can get someone for them CF team to help.

@threepointone
Copy link

I'm going to try and take a look at this

@jacoblee93
Copy link
Collaborator

@threepointone LMK if you have any questions!

Comment on lines +34 to +43
start:node: 3,
node: 3
},
versions_seen: {
__input__: {},
__start__: {
__start__: 1
},
node: {
start:node: 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed invalid JSON

Suggested change
start:node: 3,
node: 3
},
versions_seen: {
__input__: {},
__start__: {
__start__: 1
},
node: {
start:node: 2
"start:node": 3,
node: 3
},
versions_seen: {
__input__: {},
__start__: {
__start__: 1
},
node: {
"start:node": 2

const pendingWrites = await Promise.all(
(() => {
try {
return JSON.parse(String(row.pending_writes || '[]')) as PendingWriteColumn[];
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of the stringification and parsing that requires the type assertion? Is there a way to add a type guard to ensure the structure of row.pending_writes rather than forcing it?

const pending_sends = await Promise.all(
(() => {
try {
return JSON.parse(String(row.pending_sends || '[]')) as PendingSendColumn[];
Copy link
Contributor

Choose a reason for hiding this comment

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

console.error('Failed to parse pending writes:', e);
return [];
}
})().map(async (write) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This IIFE is a little hard to read, would you be able to separate the promise resolution from the iterations?

console.error('Failed to parse pending sends:', e);
return [];
}
})().map(async (send) => await this.serde.loadsTyped(send.type ?? 'json', send.value ?? ''))
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

5 participants