Skip to main content

tinystore/sql/
mod.rs

1//! The application's own SQLite databases: its tables, joins, reports and
2//! transactions, in `sql/<name>.db`. SQL stays SQL; TinyStore does the work
3//! around it: the file and its connections, migrations checked at every open,
4//! writes from many callers sharing a commit, and values that come back as
5//! they went in.
6//!
7//! ```no_run
8//! # use tinystore::sql;
9//! # #[derive(serde::Deserialize)]
10//! # struct Note { id: String, title: String, done: bool }
11//! # fn main() -> tinystore::Result<()> {
12//! # let store = tinystore::Store::open("data", Default::default())?;
13//! # let user_id = 42;
14//! let db = store.database("app").migrations("migrations").open()?;
15//! db.exec(sql!("insert into notes (id, author_id, title) values (?, ?, ?)", "0192f2a4", user_id, "Buy milk"))?;
16//! let mine: Vec<Note> = db.all(sql!("select id, title, done from notes where author_id = ?", user_id))?;
17//! # Ok(())
18//! # }
19//! ```
20//!
21//! docs/guides/sql/README.md is the guide: the TypeScript, Python and Go spellings, and
22//! why each call is as it is.
23
24mod batch;
25#[cfg(feature = "wire")]
26mod columns;
27mod database;
28mod each;
29mod engine;
30#[cfg(feature = "replication")]
31pub(crate) mod forward;
32mod included;
33mod migrations;
34mod pieces;
35mod query;
36mod rows;
37mod run;
38mod statement;
39mod tx;
40mod values;
41mod walk;
42
43pub use batch::Write;
44pub use database::{Database, DatabaseBuilder, Done};
45pub use each::Each;
46pub use migrations::Migrations;
47pub use pieces::{and, eq, has, ident, is_in, json, list, or, value};
48pub use query::{Direction, Page, Query, Table, Upsert};
49pub use statement::Sql;
50pub use tx::Tx;
51
52// What the wire takes of sql: its answers by rows and by columns, and their values.
53#[cfg(feature = "wire")]
54pub(crate) use {
55    columns::{Column, Columns},
56    database::is_query,
57    rows::{Answer, Held, Keep, Kept},
58    tx::{BOUND as TX_BOUND, HELD as TX_HELD},
59    values::Value,
60    walk::{First, Part},
61};
62
63// What the wire and the async API both take: a statement's rows, what a call wants of them, and a walk of them.
64#[cfg(any(feature = "wire", feature = "async"))]
65pub(crate) use {
66    rows::Rows,
67    run::Wanted,
68    walk::{End, Key, Taken, Walk, Walking},
69};
70
71// What the async API's queries are made of: the blocking builder's parts and statements, and a walk's rows.
72#[cfg(feature = "async")]
73pub(crate) use {
74    each::PART_BYTES,
75    query::{Paging, Parts, insert_sql, plan_of, upsert_sql},
76    rows::{Decoding, Nested},
77};
78
79// What a table's search index reads of its hits' rows.
80#[cfg(all(feature = "search", feature = "wire"))]
81pub(crate) use run::cells_on;
82#[cfg(feature = "search")]
83pub(crate) use run::{column_on, rows_on};
84
85#[cfg(test)]
86#[path = "database_tests.rs"]
87mod database_tests;
88#[cfg(test)]
89#[path = "query_tests.rs"]
90mod query_tests;