Skip to main content

sqlmodel_core/
lib.rs

1//! Core types and traits for SQLModel Rust.
2//!
3//! `sqlmodel-core` is the **foundation layer** for the entire ecosystem. It defines the
4//! traits and core data types that all other crates build on.
5//!
6//! # Role In The Architecture
7//!
8//! - **Contract layer**: `Model` and `Connection` are the primary traits implemented by
9//!   user models and database drivers.
10//! - **Data model**: `Row`, `Value`, and `SqlType` represent query inputs/outputs and
11//!   are shared across query, schema, and driver crates.
12//! - **Structured concurrency**: re-exports `Cx` and `Outcome` from asupersync so every
13//!   async database operation is cancel-correct and budget-aware.
14//!
15//! # Who Uses This Crate
16//!
17//! - `sqlmodel-macros` generates `Model` implementations defined here.
18//! - `sqlmodel-query` consumes `Model` metadata and `Value` to build SQL.
19//! - `sqlmodel-schema` inspects `Model` metadata to generate DDL.
20//! - `sqlmodel-session` depends on `Connection`, `Row`, and `Value` for unit-of-work flows.
21//! - Driver crates (`sqlmodel-postgres`, `sqlmodel-mysql`, `sqlmodel-sqlite`) implement
22//!   `Connection` and operate on `Row`/`Value`.
23//!
24//! Most applications should use the `sqlmodel` facade; reach for `sqlmodel-core` directly
25//! when writing drivers or advanced integrations.
26
27// Re-export asupersync primitives for structured concurrency
28pub use asupersync::{Budget, Cx, Outcome, RegionId, TaskId};
29
30pub mod connection;
31pub mod dynamic;
32pub mod error;
33pub mod field;
34pub mod fields_set;
35pub mod hybrid;
36pub mod identifiers;
37pub mod model;
38pub mod relationship;
39pub mod row;
40pub mod tracked;
41pub mod types;
42pub mod validate;
43pub mod value;
44
45pub use connection::{
46    Connection, Dialect, IsolationLevel, PreparedStatement, Transaction, TransactionInternal,
47    TransactionOps,
48};
49pub use error::{Error, FieldValidationError, Result, ValidationError, ValidationErrorKind};
50pub use field::{
51    Column, Field, FieldInfo, InheritanceInfo, InheritanceStrategy, ReferentialAction,
52};
53pub use fields_set::FieldsSet;
54pub use hybrid::Hybrid;
55pub use identifiers::{quote_ident, quote_ident_mysql, sanitize_identifier};
56pub use model::{
57    AttributeChange, AutoIncrement, ExtraFieldsBehavior, Model, ModelConfig, ModelEvents,
58    SoftDelete, Timestamps,
59};
60pub use relationship::{
61    Lazy, LazyLoader, LinkTableInfo, PassiveDeletes, Related, RelatedMany, RelationshipInfo,
62    RelationshipKind, find_back_relationship, find_relationship, validate_back_populates,
63};
64pub use row::Row;
65pub use tracked::TrackedModel;
66pub use types::{SqlEnum, SqlType, TypeInfo};
67pub use validate::{
68    DumpMode, DumpOptions, DumpResult, ModelDump, ModelValidate, SqlModelDump, SqlModelValidate,
69    ValidateInput, ValidateOptions, ValidateResult, apply_serialization_aliases,
70    apply_validation_aliases,
71};
72pub use value::Value;