SqlDelightStore
A persistent Store that keeps its items in a table of a SQLite database, through a SqlDriver of SQLDelight, on every platform that SqlDelightCheckpointer lists with its driver.
// Android: the checkpoints and the memories in one database.
val driver = AndroidSqliteDriver(SqlDelightCheckpointer.Schema, context, "runs.db")
val config = GraphConfig(
threadId = "plan-7",
checkpointer = SqlDelightCheckpointer(driver, KotlinxStateSerializer<Trip>()),
store = SqlDelightStore(driver).within("users", userId),
)The app creates the driver, and closes it. The store creates its table when it first needs it, with CREATE TABLE IF NOT EXISTS, so the database may be the one of a SqlDelightCheckpointer or of the app, whatever schema the driver was given. The table has one row for each item:
CREATE TABLE telar_store (
namespace TEXT NOT NULL, -- each part followed by '/', with '%' and '/' in a part written as %25 and %2F
key TEXT NOT NULL,
value TEXT NOT NULL,
updated_at INTEGER NOT NULL, -- microseconds since 1970-01-01T00:00:00Z
PRIMARY KEY (namespace, key)
)Each write is one statement, so a crash leaves the items as they were or with the write done. In the browser, the worker of SQLDelight keeps the database in memory, so the items are gone when the page is reloaded; LocalStorageStore of telar-checkpoint-browser keeps them. One instance is safe to share between coroutines.
Parameters
the database. Its dialect has to be SQLite.
the name of the table, letters, digits and _, not starting with a digit.
gives StoreItem.updatedAt, to the microsecond. Two writes of one store never get the same time, and a store starts after the last write it finds in its table, so list keeps their order also with a clock that is not precise or that went back.
Throws
if table is not a plain name.