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