Skip to Content
Motoko

How scopes map to SQLite files

sqliteStorage({ directory }) keeps each scope in its own file: <directory>/<kind>/<name>.sqlite. Each segment keeps lowercase ASCII letters, digits, _ and - and writes every other UTF-8 byte as %XX, uppercase letters included, so the mapping is one to one on case-insensitive file systems too (Alice is %41lice.sqlite, alice is alice.sqlite). A segment longer than 120 characters keeps its first 80 and a SHA-256 digest of the whole value.

A digest cannot be read back, so for such a file sqliteStorage writes its scope beside it, in <name>.scope.json, which is how sqliteScopes names it.

One file per scope, rather than table prefixes in one shared file, because each instance is its own Harness with its own connection: separate files never contend for SQLite's write lock, a scope can be copied, backed up or erased by deleting a file, and closing one instance's storage never touches another's. sqliteStorage({ path }) accepts any other layout; two scopes must never share a file without distinct table prefixes and a shared connection, which this package does not set up.