Skip to main content

drizzle_core/
lib.rs

1//! Drizzle Core - SQL generation library
2//!
3//! # `no_std` Support
4//!
5//! This crate supports `no_std` environments with an allocator:
6//!
7//! ```toml
8//! # With std (default)
9//! drizzle-core = "0.1"
10//!
11//! # no_std with allocator
12//! drizzle-core = { version = "0.1", default-features = false, features = ["alloc"] }
13//! ```
14
15#![cfg_attr(not(feature = "std"), no_std)]
16#![recursion_limit = "512"]
17
18#[cfg(not(feature = "std"))]
19extern crate alloc;
20
21// Prelude for std/alloc compatibility
22pub(crate) mod prelude {
23    // Re-export alloc types for std builds too (they're the same underlying types)
24    #[cfg(feature = "std")]
25    pub use std::{
26        borrow::Cow,
27        boxed::Box,
28        collections::{HashMap, HashSet},
29        format,
30        rc::Rc,
31        string::{String, ToString},
32        sync::Arc,
33        vec,
34        vec::Vec,
35    };
36
37    #[cfg(not(feature = "std"))]
38    pub use alloc::{
39        borrow::Cow,
40        boxed::Box,
41        format,
42        string::{String, ToString},
43        vec,
44        vec::Vec,
45    };
46
47    #[cfg(all(not(feature = "std"), feature = "alloc"))]
48    pub use alloc::{rc::Rc, sync::Arc};
49
50    // For no_std, use hashbrown instead of std::collections::{HashMap, HashSet}
51    #[cfg(not(feature = "std"))]
52    pub use hashbrown::{HashMap, HashSet};
53}
54
55pub mod bind;
56pub mod builder;
57pub mod conv;
58pub mod cte;
59pub mod dialect;
60pub mod error;
61#[macro_use]
62pub mod traits;
63pub mod expr;
64pub mod helpers;
65pub mod join;
66pub mod param;
67pub mod placeholder;
68pub mod prepared;
69#[cfg(feature = "profiling")]
70pub mod profiling;
71#[cfg(feature = "query")]
72pub mod query;
73pub mod relation;
74#[cfg(any(feature = "serde", feature = "query"))]
75#[doc(hidden)]
76pub use serde;
77#[cfg(any(feature = "serde", feature = "query"))]
78#[doc(hidden)]
79pub use serde_json;
80pub mod row;
81pub mod schema;
82pub mod sql;
83pub mod tracing;
84pub mod types;
85
86// Re-export key types and traits
87pub use bind::{BindValue, NullableBindValue, ValueTypeForDialect};
88pub use builder::{
89    BuilderInit, ExecutableState, GroupByAllowed, GroupByApplied, HavingAllowed, JoinAllowed,
90    LimitAllowed, OffsetAllowed, OrderByAllowed, WhereAllowed,
91};
92pub use dialect::{Dialect, DialectTypes, PostgresDialect, SQLiteDialect};
93pub use join::{Join, JoinType};
94pub use param::{OwnedParam, Param, ParamBind, ParamSet};
95pub use placeholder::*;
96#[cfg(feature = "query")]
97pub use relation::{CardWrap, Many, One, OptionalOne, RelationDef};
98pub use relation::{Joinable, Relation, SchemaHasTable};
99pub use row::{
100    AfterFullJoin, AfterJoin, AfterLeftJoin, AfterRightJoin, DecodeSelectedRef, ExprValueType,
101    FromDrizzleRow, GroupByIdentity, HasSelectModel, IntoGroupBy, IntoSelectTarget,
102    MarkerAggValidFor, MarkerColumnCountValid, MarkerScopeValidFor, NullProbeRow, ResolveRow,
103    RowColumnList, SQLTypeToRust, ScopePush, Scoped, SelectAs, SelectAsFrom, SelectCols,
104    SelectExpr, SelectRequiredTables, SelectStar, WrapNullable,
105};
106pub use schema::{OrderBy, asc, desc};
107pub use sql::{
108    ColumnDialect, ColumnFlags, ColumnRef, ConstraintRef, ForeignKeyRef, OwnedSQL, OwnedSQLChunk,
109    PrimaryKeyRef, SQL, SQLChunk, TableDialect, TableRef, Token,
110};
111pub use traits::*;
112
113// =============================================================================
114// Helper Macros - Used by proc macros for code generation
115// =============================================================================
116
117/// Generates `TryFrom` implementations for multiple integer types that delegate to i64.
118///
119/// Used by the `SQLiteEnum` derive macro to avoid repetitive code.
120///
121/// # Example
122/// ```rust
123/// # let _ = r####"
124/// impl_try_from_int!(MyEnum => isize, usize, i32, u32, i16, u16, i8, u8);
125/// # "####;
126/// ```
127#[macro_export]
128macro_rules! impl_try_from_int {
129    ($name:ty => $($int_type:ty),+ $(,)?) => {
130        $(
131            impl TryFrom<$int_type> for $name {
132                type Error = $crate::error::DrizzleError;
133
134                fn try_from(value: $int_type) -> ::core::result::Result<Self, Self::Error> {
135                    Self::try_from(value as i64)
136                }
137            }
138        )+
139    };
140}