Skip to content

Conversation

@kentonv
Copy link
Member

@kentonv kentonv commented Oct 22, 2024

Document that:

  • The existing storage.transaction() API applies to SQL queries.
  • There is also storage.transactionSync() for synchronous transactions.

@kentonv kentonv requested review from a team, elithrar, joshthoward and vy-ton as code owners October 22, 2024 18:31
Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

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

1 files reviewed, 1 total issue(s) found.

@github-actions github-actions bot added size/s product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ labels Oct 22, 2024
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 22, 2024

Deploying cloudflare-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7ebe21f
Status: ✅  Deploy successful!
Preview URL: https://c47a2558.cloudflare-docs-7ou.pages.dev
Branch Preview URL: https://kenton-transactions-with-sql.cloudflare-docs-7ou.pages.dev

View logs

@kentonv kentonv force-pushed the kenton/transactions-with-sqlite branch from 2e3ebd4 to 2fcdc88 Compare October 22, 2024 18:35
@github-actions
Copy link
Contributor

@kentonv kentonv force-pushed the kenton/transactions-with-sqlite branch 2 times, most recently from d767663 to 50a6805 Compare October 22, 2024 18:37
These existing links were just broken. Though, arguably they should actually go to `/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend`, perhaps? For now I just fixed the links.
@kentonv kentonv force-pushed the kenton/transactions-with-sqlite branch from ada952b to 7ebe21f Compare October 22, 2024 19:01
* When using [the SQLite-backed storage engine](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend), the `txn` object is obsolete. Any storage operations performed directly on the `ctx.storage` object, including SQL queries using [`ctx.storage.sql.exec()`](#sqlexec), will be considered part of the transaction.

### transactionSync

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a working example for reference?

@Oxyjun Oxyjun self-assigned this Oct 23, 2024
@kentonv kentonv force-pushed the kenton/transactions-with-sqlite branch 2 times, most recently from f825f3c to 3718c36 Compare October 28, 2024 19:17
@kentonv
Copy link
Member Author

kentonv commented Oct 28, 2024

I added an example but in retrospect it's a bad example because as written it doesn't actually need transactionSync(): we automatically guarantee atomicity of queries performed with no await in between.

I need a different example where the thrown exception actually rolls something back. That's the part you can only do with transactionSync().

@kentonv kentonv force-pushed the kenton/transactions-with-sqlite branch from 3718c36 to 7ebe21f Compare October 28, 2024 19:30
@kentonv
Copy link
Member Author

kentonv commented Oct 28, 2024

I reverted the example, so this is back to what was reviewed and approved previously. I'm just going to merge this as-is without an example rather than let it be delayed further.

@kentonv
Copy link
Member Author

kentonv commented Oct 28, 2024

For the record this was my example: 3718c36

But again, it's a bad example because it doesn't actually benefit from the use of transactionSync() -- the code would work fine without it, by just relying on automatic write coalescing in DO.

@kentonv kentonv enabled auto-merge (squash) October 28, 2024 19:34
@kentonv kentonv merged commit c96ef9c into production Oct 28, 2024
19 checks passed
@kentonv kentonv deleted the kenton/transactions-with-sqlite branch October 28, 2024 19:40
harshil1712 pushed a commit that referenced this pull request Dec 3, 2024
* [Durable Objects] Document transaction API changes with SQLite.

* [Durable Objects] Fix broken links to SQLite class creation docs.

These existing links were just broken. Though, arguably they should actually go to `/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend`, perhaps? For now I just fixed the links.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants