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 hybrid;
35pub mod identifiers;
36pub mod model;
37pub mod relationship;
38pub mod row;
39pub mod types;
40pub mod validate;
41pub mod value;
42
43pub use connection::{
44    Connection, Dialect, IsolationLevel, PreparedStatement, Transaction, TransactionInternal,
45    TransactionOps,
46};
47pub use error::{Error, FieldValidationError, Result, ValidationError, ValidationErrorKind};
48pub use field::{
49    Column, Field, FieldInfo, InheritanceInfo, InheritanceStrategy, ReferentialAction,
50};
51pub use hybrid::Hybrid;
52pub use identifiers::{quote_ident, quote_ident_mysql, sanitize_identifier};
53pub use model::{
54    AttributeChange, AutoIncrement, ExtraFieldsBehavior, Model, ModelConfig, ModelEvents,
55    SoftDelete, Timestamps,
56};
57pub use relationship::{
58    Lazy, LazyLoader, LinkTableInfo, PassiveDeletes, Related, RelatedMany, RelationshipInfo,
59    RelationshipKind, find_back_relationship, find_relationship, validate_back_populates,
60};
61pub use row::Row;
62pub use types::{SqlEnum, SqlType, TypeInfo};
63pub use validate::{
64    DumpMode, DumpOptions, DumpResult, ModelDump, ModelValidate, SqlModelDump, SqlModelValidate,
65    ValidateInput, ValidateOptions, ValidateResult, apply_serialization_aliases,
66    apply_validation_aliases,
67};
68pub use value::Value;