Persistence is as you'd expect -- just provide a file name when opening the database. If you don't want to persist your database, provide
":memory:" for the filename or omit the filename. A persistent database can include have non-persisted tables via the
CREATE TEMPORARY TABLE statement (opens in a new tab).
A runnable persistence example using the
wasm build is below.
Import the required packages and init the wasm:
Now create a database. To make it persisted all you need to do is pass in a filename. Omitting the filename runs the database in memory.
And finally, write then read some data to check it out:
To check that it did indeed persist, refresh this page a few times and see the number of todos grow!
You can also see a more detailed setup guide on ObservableHQ: https://observablehq.com/@tantaman/cr-sqlite-basic-setup (opens in a new tab)