Expand description
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.
let db = store.database("app").migrations("migrations").open()?;
db.exec(sql!("insert into notes (id, author_id, title) values (?, ?, ?)", "0192f2a4", user_id, "Buy milk"))?;
let mine: Vec<Note> = db.all(sql!("select id, title, done from notes where author_id = ?", user_id))?;docs/guides/sql/README.md is the guide: the TypeScript, Python and Go spellings, and why each call is as it is.
Structs§
- Database
- An application’s database: its reads, its writes, its transactions. Clones share the database, which closes with its store.
- Database
Builder - How a database opens;
Store::databasemakes one. - Done
- What a write changed: the rows, and SQLite’s rowid of the row it inserted,
0when it inserted none. The rowid is a table’s key only for aninteger primary key. - Each
- The rows of a statement, each as a
T, asDatabase::eachandQuery::eachgive them. Dropped, it stops its read and gives its reader back. - Page
- A page of a query’s rows, and the cursor that reads the next; none after the last.
- Query
- A query on a table: a value, each call returning a new one, so that the
first stays as it was.
all,one,scalar,countandlistread;updateanddeletewrite. - Sql
- A statement’s text and the values of its
?s, which are always values and never SQL, so a value cannot inject any.sql!makes one: - Table
- A table: its queries, and its rows’ inserts and upserts.
Derefs to the query of all its rows. - Tx
- A database’s transaction, from
Database::tx: its reads see its writes, and a call that fails leaves it as it was before the call. - Upsert
- What an upsert does when the row’s key is taken:
Upsert::on("id").update(["title"]).only_if(sql::eq("author_id", &user_id)). - Write
- A write of a batch: a statement, a job’s add of a queue opened from the
database,
queue.adding(&job), or an event’s append of a stream opened from it,audit.appending(name, &fields). A statement becomes one byinto:
Enums§
- Direction
- The way an order goes.
- Migrations
- A database’s migrations: a directory of
.sqlfiles named0001_notes.sql,0002_tags.sql, applied in the order of their numbers, or the files themselves by name, for a program that carries them in its binary:
Functions§
- and
- Conditions joined with
and, in parentheses, for a group inside anor; an emptyandfinds everything. - eq
- A column equal to a value, its name quoted;
Noneisis null. - has
- A JSON list in
columnholdingvalue. - ident
- A name, quoted, never SQL: a column a request chooses.
- is_in
- A column holding one of
values:in (…), written as one value SQLite reads withjson_each, so a list of any length is the same statement and an empty one finds nothing. - json
- A value kept as its JSON.
- list
- A list for
in (…), as one JSON value SQLite reads withjson_each. - or
- Conditions joined with
or, in parentheses; an emptyorfinds nothing. - value
- A value as a piece of SQL, for a column an update sets.