yang-db 0.2.0

个人使用数据库操作
Documentation
// 让 crate 内测试与 rustdoc 示例使用与外部调用方一致的稳定宏路径。
extern crate self as yang_db;

// 后端能力契约
pub mod capability;

/// 当前 yang-db crate 版本。
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

// 错误类型模块
pub mod error;

// 事务隔离级别(NG-2)
pub mod isolation;

// 跨后端管理面类型
mod pool;

mod row_lock;

mod reference;

// SQL 方言抽象(crate 内部):标识符引号、占位符风格与条件渲染的共享实现
#[cfg(any(feature = "mysql", feature = "postgres"))]
mod dialect;

// JSON 数字绑定分类(M29/NEW-11):u64 顶半区在 raw-SQL 绑定时不落入 f64 丢精度
#[cfg(any(feature = "mysql", feature = "postgres"))]
mod json_param;

// MySQL 数据库模块
#[cfg(feature = "mysql")]
pub mod mysql;

// PostgreSQL 数据库模块
#[cfg(feature = "postgres")]
pub mod postgres;

// Redis 数据库模块
#[cfg(feature = "redis")]
pub mod redis;

mod sql_types;

// 重新导出错误类型
pub use capability::{
    BackendCapabilities, BackendCapability, BackendKind, PlaceholderStyle, SafetyConstraint,
    MYSQL_CAPABILITIES, POSTGRES_CAPABILITIES, REDIS_CAPABILITIES,
};
pub use error::{DbError, DbErrorCategory};

// 重新导出事务隔离级别
pub use isolation::IsolationLevel;
pub use pool::PoolStatus;
#[doc(hidden)]
pub use reference::{__validate_field_literal, __validate_table_literal};
pub use reference::{CompareOp, FieldRef, Predicate, SelectExpr, SortOrder, SqlExpr, TableRef};

/// 创建编译期校验、进程内只初始化一次的表引用。
#[macro_export]
macro_rules! table {
    ($value:literal) => {{
        const _: () = $crate::__validate_table_literal($value);
        static VALUE: std::sync::OnceLock<$crate::TableRef> = std::sync::OnceLock::new();
        VALUE.get_or_init(|| $crate::TableRef::__from_validated_literal($value))
    }};
}

/// 创建编译期校验、进程内只初始化一次的字段引用。
#[macro_export]
macro_rules! field {
    ($value:literal) => {{
        const _: () = $crate::__validate_field_literal($value);
        static VALUE: std::sync::OnceLock<$crate::FieldRef> = std::sync::OnceLock::new();
        VALUE.get_or_init(|| $crate::FieldRef::__from_validated_literal($value))
    }};
}
pub use row_lock::RowLock;

// 重新导出 MySQL 核心类型
#[allow(deprecated)]
#[cfg(feature = "mysql")]
pub use mysql::{
    condition_to_sql_owned, condition_to_sql_owned_checked, quote_identifier, quote_qualified,
    Condition, Database, DatabaseConfig, FieldType, QueryBuilder, SqlValue, Transaction,
};

// 重新导出 PostgreSQL 核心类型(以 Pg 前缀避免与 MySQL 同名类型冲突)。
// 需要完整 PostgreSQL API 时也可直接使用 `yang_db::postgres::*`,
// 其内部类型名与 `yang_db::mysql::*` 一致,调用方式保持统一。
#[allow(deprecated)]
#[cfg(feature = "postgres")]
pub use postgres::{
    condition_to_sql_owned as pg_condition_to_sql_owned,
    condition_to_sql_owned_checked as pg_condition_to_sql_owned_checked, Condition as PgCondition,
    Database as PgDatabase, DatabaseConfig as PgDatabaseConfig, FieldType as PgFieldType,
    QueryBuilder as PgQueryBuilder, SqlValue as PgSqlValue, Transaction as PgTransaction,
};

// 重新导出 Redis 核心类型
#[cfg(feature = "redis")]
pub use redis::{RedisClient, RedisConfig, RedisPipeline, RedisTransaction, RedisValue};

// 类型别名
pub type Result<T> = std::result::Result<T, DbError>;