Durable Objecte SQLite
Yeah, SQLite in DO launched a few months ago, but it has been used by D1 for more than a year now.
If you also want to see how to think about using many DOs check out https://developers.cloudflare.com/reference-architecture/diagrams/storage/durable-object-control-data-plane-pattern/
I have a real example implementing that pattern explained in https://www.lambrospetrou.com/articles/tiddlyflare/
Also https://developers.cloudflare.com/durable-objects/best-practices/access-durable-objects-storage/#sql-in-durable-objects-vs-d1 has some light comparison between the two.
6 Replies
What are your thoughts on handling backups?
I’m also quite use to inspecting my db visually haha
@Chris Jayden If you want to use Durable Objects and have a visual way to inspect your database you could use this repo as a starting point to build upon the Durable Object with whatever custom logic you're looking to add to it.
https://github.com/outerbase/starbasedb
If you deploy the DO via the code from this repository then you can see your database by visiting https://starbasedb.YOUR-IDENTIFIER.workers.dev/studio (the
/studio
endpoint). Just tossing that out as an option for you so you know there's possibilities in making visual db exploration happen!
FWIW – StarbaseDB is a Durable Object 🙂
We usually add a VERY thin layer in our workers to call "debug" RPC methods on our Durable Objects to return useful information during debugging.
Having always access to the data itself is not often useful since we don't want to manually be modifying stuff in production, but there are many libraries like the one shared above or you can write your own endpoint accepting some SQL to run for you in a given DO. Always be careful with this kind of tools though cause you expose them to the world. Proper auth/security should be used.
Thanks, I did come across starbase while researching. NIcely done. Al though i run my own setup already.
Noted! I figured something like that. I'll have some routes behind an admin account that cna display information.
And for backups, you'd basically reimplement this idea?
https://developers.cloudflare.com/d1/reference/time-travel/#terminology
Okay, while trying to get some proof of concept setup for my smaller routes, my biggest hurdle has been typescript so far and i think it might be a deal breaker :(. The inference is not good enough.
https://discord.com/channels/595317990191398933/1329138972403830944
My suggestion is to always put return types in your DO RPC functions explicitly. I also had vscode and Typescript choke on the RPC types. They do need improvements for sure.
Adding them explicitly sometimes help though.
What do you mean reimplement that idea? D1 uses the same API the DO provides to you with bookmarks, so you can just revert to a previous bookmark if you want to go back in time. So yeah, you would use the same underlying DO APIs.
I didn't phrase that right sorry. But yes exactly, thanks.
Yeah, I'm doing that, but to no avail unfortunately. Hopefully this will get improved, because you can't pass
Promise<any>
or Promise<unknown<
as the return type either.
It's great chatitng with you about this btw. Appreciate the help