persistant_macros/lib.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! The compile-time SQL macro behind `persistant::sql!` (feature `sql-macros` of the `persistant`
3//! crate). A proc-macro crate cannot be extended, only wrapped, so this is PersistAnt's own thin
4//! wrapper over `unisql-macro-core`; see `docs/COMPILE-TIME-SQL.md`.
5//!
6//! ```text
7//! const FIND: persistant::Sql = persistant::sql!(
8//! source = postgres, targets = [postgres, sqlite, mysql],
9//! "SELECT id, email FROM users WHERE id = $1"
10//! );
11//! ```
12//!
13//! Arguments, in any order, then the statement as the last argument (a string literal):
14//! `source` (required), `targets` (required, at least one), `allow`, `requires`, `forbids`, and
15//! `crate = path` (where the expansion finds `Query`, default `::persistant::embed`). The statement is
16//! parsed in the source dialect and translated for every named target at build time; whatever cannot
17//! be is a compile error. Nothing is looked up in a database and no schema is read yet (the
18//! catalog-based checks are a later stage).
19
20mod checker;
21mod imp;
22
23/// Check and translate a literal statement at build time. See the crate documentation.
24#[proc_macro]
25pub fn sql(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
26 imp::sql(input.into()).into()
27}