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 pagination;
67pub mod param;
68pub mod placeholder;
69pub mod prepared;
70#[cfg(feature = "profiling")]
71pub mod profiling;
72#[cfg(feature = "query")]
73pub mod query;
74pub mod relation;
75#[cfg(any(feature = "serde", feature = "query"))]
76#[doc(hidden)]
77pub use serde;
78#[cfg(any(feature = "serde", feature = "query"))]
79#[doc(hidden)]
80pub use serde_json;
81pub mod row;
82pub mod schema;
83pub mod sql;
84pub mod tracing;
85pub mod types;
86
87// Re-export key types and traits
88pub use bind::{BindValue, NullableBindValue, ValueTypeForDialect};
89pub use builder::{
90    BuilderInit, ExecutableState, GroupByAllowed, GroupByApplied, HavingAllowed, JoinAllowed,
91    LimitAllowed, OffsetAllowed, OrderByAllowed, WhereAllowed,
92};
93pub use dialect::{Dialect, DialectTypes, PostgresDialect, SQLiteDialect};
94pub use join::{Join, JoinType};
95pub use pagination::PaginationArg;
96pub use param::{OwnedParam, Param, ParamBind, ParamSet};
97pub use placeholder::*;
98#[cfg(feature = "query")]
99pub use relation::{CardWrap, Many, One, OptionalOne, RelationDef};
100pub use relation::{Joinable, Relation, SchemaHasTable};
101pub use row::{
102    AfterFullJoin, AfterJoin, AfterLeftJoin, AfterRightJoin, DecodeSelectedRef, ExprValueType,
103    FromDrizzleRow, GroupByIdentity, HasSelectModel, IntoGroupBy, IntoSelectTarget,
104    MarkerAggValidFor, MarkerColumnCountValid, MarkerScopeValidFor, NullProbeRow, ResolveRow,
105    RowColumnList, SQLTypeToRust, ScopePush, Scoped, SelectAs, SelectAsFrom, SelectCols,
106    SelectExpr, SelectRequiredTables, SelectStar, WrapNullable,
107};
108pub use schema::{OrderBy, asc, desc};
109pub use sql::{
110    ColumnDialect, ColumnFlags, ColumnRef, ColumnSqlRef, ConstraintRef, ForeignKeyRef, OwnedSQL,
111    OwnedSQLChunk, PrimaryKeyRef, SQL, SQLChunk, TableDialect, TableRef, TableSqlRef, Token,
112};
113pub use traits::*;
114
115// =============================================================================
116// Helper Macros - Used by proc macros for code generation
117// =============================================================================
118
119/// Generates `TryFrom` implementations for multiple integer types that delegate to i64.
120///
121/// Used by the `SQLiteEnum` derive macro to avoid repetitive code.
122///
123/// # Example
124/// ```rust
125/// # let _ = r####"
126/// impl_try_from_int!(MyEnum => isize, usize, i32, u32, i16, u16, i8, u8);
127/// # "####;
128/// ```
129#[macro_export]
130macro_rules! impl_try_from_int {
131    ($name:ty => $($int_type:ty),+ $(,)?) => {
132        $(
133            impl TryFrom<$int_type> for $name {
134                type Error = $crate::error::DrizzleError;
135
136                fn try_from(value: $int_type) -> ::core::result::Result<Self, Self::Error> {
137                    Self::try_from(value as i64)
138                }
139            }
140        )+
141    };
142}