Skip to main content

qbrs_core/
lib.rs

1//! The query-building half of [qbrs](https://docs.rs/qbrs): scope tracking,
2//! expressions, the `SELECT`/`INSERT`/`UPDATE`/`DELETE` builders, and the SQL
3//! renderer. No I/O, no async runtime, no driver — and no dependency at all
4//! unless a schema asks for one (the `chrono`, `uuid` and `decimal` features).
5//!
6//! Depend on `qbrs` rather than this crate directly; it re-exports everything
7//! here alongside `#[derive(Table)]`, `#[derive(FromRow)]`, `label!` and
8//! `with!`, which have to be proc macros and so live in `qbrs-macros`.
9//!
10//! [`scope`] is the load-bearing module: a query's FROM/JOIN set is a flat
11//! type-level list, and every "is this column in scope, and is the join making
12//! it nullable?" question is a lookup in it. Reading that module first makes
13//! the rest of the crate follow.
14
15// Every builder struct carries a `PhantomData<fn() -> (D, Scope, ...)>`
16// marker tuple of compile-time-only type tags. That's a deliberate,
17// repeated pattern rather than a complexity smell, and there's no simpler
18// form to factor it into, so the lint is suppressed crate-wide.
19#![allow(clippy::type_complexity)]
20
21pub mod cte;
22pub mod delete;
23pub mod dialect;
24pub mod expr;
25pub mod insert;
26pub mod prepare;
27pub mod raw;
28pub mod render;
29pub mod row;
30pub mod scope;
31pub mod select;
32pub mod statement;
33pub mod update;
34pub mod window;
35
36#[cfg(test)]
37mod tests {
38    use crate::expr::Value;
39
40    #[test]
41    fn a_value_names_the_sql_type_it_came_from() {
42        // `qbrs-sqlx` reports this name when a column type is enabled here
43        // and not there, so every variant that can exist has to have one.
44        assert_eq!(Value::I64(1).type_name(), "BigInt");
45        assert_eq!(Value::NullText.type_name(), "Text");
46        #[cfg(feature = "chrono")]
47        assert_eq!(Value::NullTimestamptz.type_name(), "Timestamptz");
48        #[cfg(feature = "decimal")]
49        assert_eq!(Value::NullNumeric.type_name(), "Numeric");
50    }
51}