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

Docs feature branch: SQLite in DO #16903

Merged
merged 26 commits into from
Sep 26, 2024
Merged

Docs feature branch: SQLite in DO #16903

merged 26 commits into from
Sep 26, 2024

Conversation

vy-ton
Copy link
Contributor

@vy-ton vy-ton commented Sep 18, 2024

TODO:

  • Overview
  • @vy-ton Pricing, Limits
  • Get started walkthrough
  • @vy-ton (New) Best Practices > Query embedded SQL database: code examples for different SQL tasks
  • @vy-ton API > Transactional Storage: add SQL API
  • PITR
  • Reference > Durable Objects migrations: add new_sqlite_classes
  • @vy-ton (New) Platform: D1 vs DO comparison
  • @vy-ton Changelog

TODO unrelated to SQLite-in-DO:

Later PR:

  • (New) Examples > Use the SQL API
  • (New) Examples > SQL schema migrations
  • - [ ] Add examples of RPC (default; recommended) vs fetch (WebSockets) and clarify differences between each approach (and that both can be used) @elithrar
  • New /durable-objects/build/scaling-durable-objects/ doc that talks about how to scale horizontally, data model, and manage DOs. @elithrar

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

cloudflare-workers-and-pages bot commented Sep 18, 2024

Deploying cloudflare-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 34948fe
Status: ✅  Deploy successful!
Preview URL: https://3a888724.cloudflare-docs-7ou.pages.dev
Branch Preview URL: https://sqlite-in-do.cloudflare-docs-7ou.pages.dev

View logs

Copy link

github-actions bot commented Sep 18, 2024

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/durable-objects/api/storage-api/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/api/storage-api/
https://developers.cloudflare.com/durable-objects/best-practices/access-durable-objects-storage/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/best-practices/access-durable-objects-storage/
https://developers.cloudflare.com/durable-objects/platform/limits/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/platform/limits/
https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/reference/durable-objects-migrations/
https://developers.cloudflare.com/durable-objects/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/
https://developers.cloudflare.com/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/
https://developers.cloudflare.com/workers/platform/storage-options/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/workers/platform/storage-options/
https://developers.cloudflare.com/durable-objects/api/alarms/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/api/alarms/
https://developers.cloudflare.com/durable-objects/platform/pricing/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/platform/pricing/
https://developers.cloudflare.com/durable-objects/reference/in-memory-state/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/reference/in-memory-state/
https://developers.cloudflare.com/workers/platform/pricing/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/workers/platform/pricing/
https://developers.cloudflare.com/durable-objects/api/websockets/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/api/websockets/
https://developers.cloudflare.com/durable-objects/examples/durable-object-in-memory-state/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/examples/durable-object-in-memory-state/
https://developers.cloudflare.com/durable-objects/reference/websockets/ https://sqlite-in-do.cloudflare-docs-7ou.pages.dev/durable-objects/reference/websockets/

@vy-ton
Copy link
Contributor Author

vy-ton commented Sep 18, 2024

We're going to use sqlite-in-do as the docs feature branch. Please open any docs PR against this branch so we can merge it pre-launch.

(New) Examples > Use the SQL API

@harshil1712 Could you work on adding an example or even multiple? Kenton's example in the public blog should be available in docs as well.

src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
// query returned zero results
}

console.log(cursor.toArray()); // prints [{ artistid: 456, artistname: 'Bob' },{ artistid: 789, artistname: 'Charlie' }]
Copy link
Contributor

Choose a reason for hiding this comment

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

I get that this example is showing multiple things, but it seems kinda weird to have cursor.toArray() in this example. It would be better to have individual examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returned cursor and raw() iterator iterate over the same query results and can be combined.

Wanted this example embedded here to highlight the above bullet.

There are individual examples for different tasks below on this page

src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved
src/content/docs/durable-objects/api/storage-api.mdx Outdated Show resolved Hide resolved

Durable Objects are a powerful compute API that provides a compute with storage building block. Each Durable Object has private, transactional and strongly consistent storage attached. By default, key-value storage is available. SQL storage(/durable-objects/best-practices/access-durable-objects-storage/#sql-storage) is available on a new beta version of Durable Objects.

You should use Durable Objects storage to persist state durably on-disk that needs to survive beyond the lifetime of a Durable Object, that is, eviction of a Durable Object from memory. A Durable Object is alive based on the request traffic incoming to the instance. There are also normal operations like [code deployments](/workers/configuration/versions-and-deployments/) that trigger a Durable Object to reset. For these reasons, Durable Objects storage is recommended for persisting [in-memory state](/durable-objects/reference/in-memory-state/).
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this paragraph is trying to tell me.

I think it's trying to make the distinction between in-memory and on-disk storage, but that doesn't follow from the first paragraph. Perhaps the first paragraph needs to mention that DOs persist across requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked, lmk if it helped.


**D1 is a managed database product.**

D1 fits into a familiar architecture for developers, where application servers communicate with a database over the network. Application servers are typically Workers; however, D1 also supports external, non-Worker access via an [HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database).
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think it's a missed opportunity not to highlight the framework support that D1 has and that DO probably cannot have.

@justin-mp
Copy link
Contributor

I have no idea where this comment went, but @vy-ton asked

I see the below in workers-types. Is this changing with the updated APIs?

declare abstract class SqlStorageCursor {
 ...
 get columnNames(): string[];
 ...
}```

This defines columnNames as a read-only property, despite looking like a function. https://www.typescriptlang.org/docs/handbook/2/classes.html#getters--setters

@vy-ton vy-ton merged commit b8f4797 into production Sep 26, 2024
14 checks passed
@vy-ton vy-ton deleted the sqlite-in-do branch September 26, 2024 02:34
patriciasantaana pushed a commit that referenced this pull request Sep 26, 2024
SQLite in DO docs

---------

Co-authored-by: Kenton Varda <[email protected]>
Co-authored-by: justin-mp <[email protected]>
Co-authored-by: Jun Lee <[email protected]>
elithrar pushed a commit that referenced this pull request Oct 15, 2024
SQLite in DO docs

---------

Co-authored-by: Kenton Varda <[email protected]>
Co-authored-by: justin-mp <[email protected]>
Co-authored-by: Jun Lee <[email protected]>
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/ product:workers Related to Workers product size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants