Skip to main content

sql_builder/extension/
mod.rs

1//! SQL that only one backend understands: PostgreSQL's and SQLite's own operators,
2//! expressions and functions.
3
4/// Declares a backend's binary operators: the enum, each variant's documentation led by
5/// the SQL it renders as, and `sql()` giving that SQL to the backend's query builder.
6macro_rules! binary_operators {
7    (
8        $(#[$meta:meta])*
9        pub enum $name:ident {
10            $($(#[$doc:meta])* $variant:ident = $sql:literal,)+
11        }
12    ) => {
13        $(#[$meta])*
14        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
15        pub enum $name {
16            $(
17                #[doc = concat!("`", $sql, "`:")]
18                $(#[$doc])*
19                $variant,
20            )+
21        }
22
23        impl $name {
24            /// The operator as written in SQL.
25            pub(crate) const fn sql(self) -> &'static str {
26                match self {
27                    $(Self::$variant => $sql,)+
28                }
29            }
30        }
31    };
32}
33
34pub mod postgres;
35
36pub mod sqlite;