1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Core primitives for keelson.
//!
//! Everything else — the three dialect crates, the generated models, the backend
//! adapters — is built out of what is defined here:
//!
//! - [`Value`], the bound argument. keelson carries its own value enum instead of
//! being generic over a driver's parameter type, which keeps [`Expression`] free
//! of type parameters and makes a built query's arguments inspectable.
//! - [`Dialect`], the per-database syntax decisions, and nothing else.
//! - [`Expression`], a fragment that can render itself, and [`SqlWriter`], which
//! owns the SQL buffer, the argument list and the placeholder counter together
//! so that nesting re-indexes for free.
//! - [`Mod`], the composition unit: a tuple of mods is a mod, and so is
//! `Option<M>`, `Vec<M>` and `[M; N]`.
//! - [`Query`] and [`QueryType`], the little a runnable statement owes the layers
//! above.
//!
//! Two properties are worth stating up front because the rest of the design leans
//! on them. Rendering is **infallible** — `write_sql` returns nothing, and the one
//! genuine failure (a named argument asked of a dialect without them) is recorded
//! on the writer and surfaced once, by [`build`]. And **no public type carries a
//! lifetime parameter**: identifiers and raw SQL are stored as
//! `Cow<'static, str>`, so a query type is `SelectQuery`, never `SelectQuery<'a>`.
//! The only lifetime in this crate is the transient one on [`SqlWriter`], which
//! borrows the dialect for the duration of a single build.
//!
//! Building is entirely synchronous and driver-independent: it produces a `String`
//! and a `Vec<Value>` and nothing more.
//!
//! ```
//! # use keelson_core::{Dialect, Expression, SqlWriter, Value, build};
//! #[derive(Debug)]
//! struct AgeAtLeast(i32);
//!
//! impl Expression for AgeAtLeast {
//! fn write_sql(&self, w: &mut SqlWriter<'_>) {
//! w.push_str("(");
//! w.push_quoted(&["age"]);
//! w.push_str(" >= ");
//! w.push_arg(self.0);
//! w.push_str(")");
//! }
//! }
//!
//! # #[derive(Debug)]
//! # struct Psql;
//! # impl Dialect for Psql {
//! # fn write_arg(&self, w: &mut SqlWriter<'_>, position: usize) {
//! # w.push_str("$");
//! # w.push_str(&position.to_string());
//! # }
//! # fn write_quoted(&self, w: &mut SqlWriter<'_>, s: &str) {
//! # w.push_str("\"");
//! # w.push_str(s);
//! # w.push_str("\"");
//! # }
//! # }
//! let (sql, args) = build(&Psql, &AgeAtLeast(21))?;
//! assert_eq!(sql, r#"("age" >= $1)"#);
//! assert_eq!(args, vec![Value::I32(21)]);
//! # Ok::<_, keelson_core::Error>(())
//! ```
//!
//! # Where this sits
//!
//! Layer 0 of keelson: the vocabulary, and the only crate every other one
//! depends on. Above it sit the three Layer 1 dialects
//! ([keelson-psql](https://docs.rs/keelson-psql), [keelson-mysql](https://docs.rs/keelson-mysql),
//! [keelson-sqlite](https://docs.rs/keelson-sqlite)), which is where a user starts —
//! a statement type comes from a dialect, never from here. Layer 2
//! ([keelson-exec](https://docs.rs/keelson-exec)) runs what [`build`] returns, and Layer 3
//! ([keelson-models](https://docs.rs/keelson-models)) is written against the
//! [`clause`] traits defined here. The whole map, and one dependency line for
//! it, is the [keelson](https://docs.rs/keelson) facade crate.
pub use Dialect;
pub use ;
pub use ;
pub use ;
pub use ;
/// The derive macros, re-exported behind the `macros` feature.
///
/// [`Bind`](macro@Bind) writes the [`ToValue`]/[`FromValue`] pair for a
/// newtype — the bound a keelson-gen column override must satisfy.
/// [`FromRow`](macro@FromRow) maps a result row onto a struct; the trait it
/// implements lives in keelson-exec, which any user of it already depends on.
/// Both are documented in the keelson-macros crate.
///
/// `keelson_core::Bind` is the derive, `keelson_exec::Bind` the trait: two
/// namespaces, so importing both is fine.
pub use ;
/// The scanner each dialect's `sql!` forwards to. Not called directly.
pub use sql_with as __sql_with;
pub use ;
/// Stand-in dialects for tests. See [`dialect::testing`].
pub use testing;