Expand description
TinyStore: an embedded data runtime on SQLite.
One directory, held by one Store through its LOCK, a file per engine.
The store gives every engine the clock it reads, the memory budget its work
reserves from, the background work it runs and the errors they all share.
Re-exports§
pub use kv::locks;
Modules§
- backup
- A backup of a whole store while its program runs, as one zip: every
engine’s files, each copied as one moment of its engine, the files of the
program’s it is told to take, and a manifest of their sizes and SHA-256;
and its restore into an empty directory, before a store opens there,
checking every byte. The guide is
docs/guides/backup/README.md. - blobs
- The application’s files: bytes by path in named sets, written whole and
replaced whole, checked against their SHA-256 when read whole, and kept
inline in
blobs/blobs.dbup to 16 KiB or as a file each past it. - channels
- Channels: messages a program publishes on a named channel, which every subscriber listening at that moment receives, in memory and at most once. A message published while nobody listens is gone; work that must be done is a job’s, and events to read again are records’. docs/guides/channels/README.md is the book.
- config
- A program’s settings as one typed value, declared in layers: the
declaration in code, then files and the environment, each declaring
again what the ones before it gave; and, for the settings marked
Live, changes made while the program runs, kept in kv.db, over every layer until they are reset, and seen by every handle at once. The book isdocs/guides/config/README.md. - console
- The console: a logger’s lines as they are printed, pretty for a person at a terminal and one JSON object a line for a collector, the same bytes the Go, Bun and Python loggers print. It needs no store and links no SQLite; a store’s logger prints the same lines and keeps them too.
- engine
- What engines use of their store. An application never imports this module: it opens engines, and engines call these.
- jobs
- Work an application must do later, or now but outside the request that asked for it: queues of jobs in the order of their time in jobs.db, a handler run on each as it falls due, retries, repeats, and ids that find a job again.
- kv
- The application’s current state: values by key in buckets, branches a user clears in one call, expiry on the store’s clock, versions for writes that must not lose another’s, and counters, rate limits, quotas and answers kept once a key beside them.
- limits
- The bounds one call meets, each by the name a
limiterror gives it. The error carries three facts a program reads without parsing its text:limit, the bound’s name;wanted, what the call would have taken of it; andbound, the most it takes. - metrics
- Numbers that move over time: a program’s requests, its queue’s length, how
long its calls take, and samples other programs send, kept exactly in
metrics.dband read back by series and range. - pipe
- A connection in memory: the wire’s frames to a store in this process, with no socket between. The FFI hands its bytes here, so Bun, Node, Python and Go reach the core through the same session a server gives a socket, and a server gives each of its clients one.
- records
- An application’s logs and events: named streams of events in
records.db, written whole, read back by time and by what they hold. - replication
- Replication: every store a node, each file written by one home and copied by the nodes that ask for it, as the nodes guide describes.
- search
- Documents set by id in a named index and found again by their words, by
vectors the program’s own model gave them, or by both, in
search.db: words in any language and any script, a typo forgiven, the exact best by BM25 over the fields and their weights; vectors the exact best by cosine; either kept to the documents a filter passes, made ofeq,is_in,range,missing,orandandas a query’s conditions are ofsql::eqand the rest. - sql
- The application’s own SQLite databases: its tables, joins, reports and
transactions, in
sql/<name>.db. SQL stays SQL; TinyStore does the work around it: the file and its connections, migrations checked at every open, writes from many callers sharing a commit, and values that come back as they went in. - typos
- The words nearest a misspelt one: a dictionary of words in an FST, read
through a Levenshtein automaton that counts two letters swapped as one
edit. A dictionary’s caller says how many edits it looks across, since
search reads a document’s word of five letters with one; a name a person
may have misspelt, a config’s key, a search’s filter, a command or a
tool, is read by one rule,
meant. Config, the command line, MCP and search use it, none of them importing another, and a suggestion it gives changes nothing by itself.
Macros§
- sql
- A statement and the values of its
?s, in order:sql!("select * from notes where author_id = ? and done = ?", user_id, false).
Structs§
- Cancellation
Token - Stops the reads of a call from another thread, at once or after a
timeout: a read under way stops, gives its reader back and fails
Cancelled, and one that has not started fails before it takes one. - Constraint
- A constraint a write broke, as SQLite names it: its kind always, and the table and the columns, or the constraint’s own name, when SQLite says them.
- Error
- An error that names what failed:
kv bucket sessions: key "a": not found. - Memory
- Options
- How a store opens.
- Reservation
- Bytes taken from a store’s memory, given back when dropped.
- Store
- One directory of engine files, held by one store at a time through its
LOCK. Engines open against a store and close with it, the last opened first: atclose, or when the last clone of the store is dropped. - System
Clock - The system’s clock.
- Test
Clock - A clock a test moves by hand. It never moves backwards: engines keep watermarks and leases by it, and a step back would make them lie.
- Transaction
- A transaction as the handles it takes in see it: the writer it holds, the file a handle must be kept in, the bound it ends within, and what runs once it ends.
- Tx
- A transaction of the store, given to the function
Store::txruns.
Enums§
- Calendar
- The span of the calendar a bucket covers, in the time zone an aggregate gives with it.
- Constraint
Kind - A unique or a primary key already held is
conflict; any other isinvalid. - Durability
- How far a commit goes before it returns: a setting of a store’s files,
kv.db,jobs.dband each database’s, whichOptionsgives for them all and a database may say for itself. - Error
Kind - What went wrong, with the same meaning in every engine, on the wire and in every SDK.
Traits§
- Clock
- Where a store reads the time. Every engine reads it through the store, so a test that moves one clock moves them all.
- Key
- What names a key, an owner or a folder: text, or an integer spelled in
decimal, so that
42and"42"are one key. - TxHandle
- A handle a transaction of its file takes in with
tx.with(&handle): a bucket or counters, and a queue, from the store or from a database.
Functions§
- unix_
millis - Milliseconds since the Unix epoch; negative before it.
- unix_
nanos - Nanoseconds since the Unix epoch; negative before it.