sqlmodel-core 0.4.3

Core types and traits for SQLModel Rust
//! Core types and traits for SQLModel Rust.
//!
//! `sqlmodel-core` is the **foundation layer** for the entire ecosystem. It defines the
//! traits and core data types that all other crates build on.
//!
//! # Role In The Architecture
//!
//! - **Contract layer**: `Model` and `Connection` are the primary traits implemented by
//!   user models and database drivers.
//! - **Data model**: `Row`, `Value`, and `SqlType` represent query inputs/outputs and
//!   are shared across query, schema, and driver crates.
//! - **Structured concurrency**: re-exports `Cx` and `Outcome` from asupersync so every
//!   async database operation is cancel-correct and budget-aware.
//!
//! # Who Uses This Crate
//!
//! - `sqlmodel-macros` generates `Model` implementations defined here.
//! - `sqlmodel-query` consumes `Model` metadata and `Value` to build SQL.
//! - `sqlmodel-schema` inspects `Model` metadata to generate DDL.
//! - `sqlmodel-session` depends on `Connection`, `Row`, and `Value` for unit-of-work flows.
//! - Driver crates (`sqlmodel-postgres`, `sqlmodel-mysql`, `sqlmodel-sqlite`) implement
//!   `Connection` and operate on `Row`/`Value`.
//!
//! Most applications should use the `sqlmodel` facade; reach for `sqlmodel-core` directly
//! when writing drivers or advanced integrations.

// Re-export asupersync primitives for structured concurrency
pub use asupersync::{Budget, Cx, Outcome, RegionId, TaskId};

pub mod connection;
pub mod dynamic;
pub mod error;
pub mod field;
pub mod fields_set;
pub mod hybrid;
pub mod identifiers;
pub mod model;
pub mod relationship;
pub mod retry;
pub mod row;
pub mod tracked;
pub mod types;
pub mod validate;
pub mod value;

/// Cancellation-injection test support.
///
/// Only compiled under `#[cfg(any(test, feature = "test-support"))]` so the
/// published default build carries none of it.
#[cfg(any(test, feature = "test-support"))]
pub mod test_support;

/// Optional `From`/`TryFrom`/`FromValue` impls for chrono, uuid, and rust_decimal
/// types (features `chrono`, `uuid`, `decimal`).
#[cfg(any(feature = "chrono", feature = "uuid", feature = "decimal"))]
pub mod external_types;

pub use connection::{
    Connection, Dialect, IsolationLevel, PreparedStatement, Transaction, TransactionInternal,
    TransactionMode, TransactionOps, TransactionOptions,
};
pub use error::{
    Error, FieldValidationError, Result, TransactionErrorKind, TypeError, ValidationError,
    ValidationErrorKind,
};
pub use field::{
    Column, Field, FieldInfo, InheritanceInfo, InheritanceStrategy, ReferentialAction,
};
pub use fields_set::FieldsSet;
pub use hybrid::Hybrid;
pub use identifiers::{quote_ident, quote_ident_mysql, sanitize_identifier};
pub use model::{
    AttributeChange, AutoIncrement, ExtraFieldsBehavior, Model, ModelConfig, ModelEvents,
    SoftDelete, Timestamps,
};
pub use relationship::{
    Lazy, LazyLoader, LinkTableInfo, PassiveDeletes, Related, RelatedMany, RelationshipInfo,
    RelationshipKind, find_back_relationship, find_relationship, validate_back_populates,
};
pub use retry::{RetryDecision, RetryPolicy, retry_transaction};

/// The cancellation reason if `cx` has already been cancelled, else `None`.
///
/// Every driver calls this at the start of each `Connection` operation so a
/// statement is never sent on behalf of a cancelled context:
///
/// ```ignore
/// if let Some(reason) = sqlmodel_core::cancel_requested(cx) {
///     return Outcome::Cancelled(reason);
/// }
/// ```
#[must_use]
pub fn cancel_requested(cx: &Cx) -> Option<asupersync::CancelReason> {
    if cx.is_cancel_requested() {
        Some(
            cx.cancel_reason()
                .unwrap_or_else(|| asupersync::CancelReason::user("operation cancelled")),
        )
    } else {
        None
    }
}
pub use row::Row;
pub use tracked::TrackedModel;
pub use types::{SqlEnum, SqlType, TypeInfo};
pub use validate::{
    DumpMode, DumpOptions, DumpResult, ModelDump, ModelValidate, SqlModelDump, SqlModelUpdate,
    SqlModelValidate, UpdateInput, UpdateOptions, ValidateInput, ValidateOptions, ValidateResult,
    apply_serialization_aliases, apply_validation_aliases,
};
pub use value::Value;