Expand description
ORM Facade — 统一访问 sz-orm 全家桶
§设计目标
减少 sz-rust-addons-operate、sz-rust-sz300 等业务包对 sz-orm-* 子包的穿透依赖。
业务包应通过 sz_rust_orm_facade::* 访问 ORM 功能,而非直接依赖 sz-orm-core、
sz-orm-auth、sz-orm-mqtt、sz-orm-scheduler、sz-orm-logger。
§使用示例
ⓘ
// 业务包统一通过 facade 访问(推荐)
use sz_rust_orm_facade::{Pool, Value, Model, ModelExt, Authorizer, JwtAuthenticator, MqttConfig, QoS};
use sz_rust_orm_facade::repository::{Repository, WhereCondition, WhereOp};
use sz_rust_orm_facade::scheduler::{CronScheduler, JobHandler, ScheduledTask, Scheduler};Re-exports§
pub use pool_config::SqlxPoolConfig;
Modules§
- auth
- 认证子模块(Credentials / User / Claims 等数据结构)
- find_
with_ related - 关联查询子模块(find_with_related eager/join/subquery 策略)
- hooks
- Hooks 子模块(生命周期钩子)
- jwt
- JWT 子模块(JwtEncoder / JwtClaims 等编码工具)
- l2_
cache - L2 缓存子模块(二级缓存共享层)
- logger
- 日志子模块(Logger / LogEntry / LogLevel 等)
- migration
- 迁移子模块(schema migration)
- pool_
config - 连接池配置调优(L2 方案:sqlx 配置调优,不修改 sz-orm 上游)
- repository
- 仓储子模块(Repository trait + WhereCondition/WhereOp 条件构造)
- scheduler
- 调度器子模块(CronScheduler / JobHandler / ScheduledTask 等)
Macros§
- query
- Compile-time SQL validation with optional real DB verification.
- sql_
string - Compile-time SQL validation macro.
Structs§
- Active
Config - Alert
- 告警事件,由
SaturationGauge/SlaMonitor等组件在检测到异常时产生, 通过AlertHook分发到下游(日志、Webhook 等)。 - Aliyun
OssStorage - 阿里云 OSS 存储后端(Mock 实现)
- Backpressure
Policy - 背压策略
- Belongs
To - 多对一关系配置
- Belongs
ToMany - 多对多关系配置
- Built
Query - 参数化查询构造结果
- Cron
Expr - 调度器根级 re-export(供 core 内部 dogfood 使用)
- Cron
Scheduler - 调度器根级 re-export(供 core 内部 dogfood 使用)
- Default
WebSocket Handler - Default WebSocket handler that tracks connections and echoes messages.
- Delete
Query - DELETE 查询构造器
- Distributed
Rate Limiter - 分布式限流器
- Error
Budget - 错误预算(Error Budget),基于 SLO 目标和滑动时间窗口。
- Error
Rate Counter - 错误率计数器,基于滑动时间窗口统计错误率。
- Fixed
Window Rate Limiter - 固定窗口限流器
- HasMany
- 一对多关系配置
- HasOne
- 一对一关系配置
- Huawei
ObsStorage - 华为云 OBS 存储后端(Mock 实现)
- InMemory
Backend - 内存后端(模拟 Redis)
- InMemory
Queue - Insert
Query - INSERT 查询构造器
- JwtAuthenticator
- Authenticator that issues and verifies real HS256 JWTs.
- Kafka
Config - Latency
Histogram - 延迟分位数直方图。
- Local
Storage - LogAlert
Hook - 将告警输出到标准错误流的简单实现。
- Memory
Cache - Message
- 消息体
- Morph
Many - 多态一对多配置(父模型侧)
- MorphTo
- 多态反向配置(子模型侧)
- Mqtt
Config - Mqtt
Message - Mqtt
Plugin - Mqtt
Topic - Multi
Level Cache - Nats
Config - Otel
Tracer - A compatibility wrapper that exposes the same
Tracerinterface as the OpenTelemetry SDK but is implemented internally by delegating every call to aSzTracer. - Pool
- 连接池核心实现
- Pool
Config - Pool
Config Builder - Pulsar
Config - Qiniu
Kodo Storage - 七牛云 Kodo 存储后端(Mock 实现)
- Query
- 查询构造器入口
- Queue
Config - Rate
Limit Headers - 限流响应头
- Rate
Limit Result - Rbac
Authorizer - Role-based authorizer backed by a
role -> permissionsmap. - Recording
JobHandler - 调度器根级 re-export(供 core 内部 dogfood 使用)
JobHandlerthat records the IDs of every task it has handled, in the order they were handled. Useful for tests that need to assert which tasks fired and in what order. - S3Storage
- AWS S3 存储后端(Mock 实现)
- Saturation
Gauge - 饱和度告警仪表盘。
- Scheduled
Task - 调度器根级 re-export(供 core 内部 dogfood 使用)
- Select
Query - SELECT 查询构造器
- SlaMonitor
- SLA 监控器,按操作名聚合延迟与错误统计,并生成
SlaReport。 - SlaReport
- SLA 监控报告快照,由
SlaMonitor::report生成。 - Sliding
Window Rate Limiter - Span
- SpanLog
- SqlComplexity
Score - SQL 复杂度评分结果。
- Storage
Builder - Storage
Config - SzTracer
- Tencent
CosStorage - 腾讯云 COS 存储后端(Mock 实现)
- Timestamp
Fields - 时间戳字段配置
- Token
Bucket Rate Limiter - UpYun
Storage - 又拍云存储后端(Mock 实现)
- Update
Query - UPDATE 查询构造器
- Whitelist
Validator - 白名单校验器,限制 SQL 只能访问允许的表和列。
- WsServer
Enums§
- Alert
Level - 告警级别。
- Cache
Error - 缓存特有错误
- Complexity
Level - SQL 复杂度等级。
- DbError
- 数据库错误类型
- DbType
- 支持的数据库类型
- MqError
- MqProvider
- Mqtt
Error - Overflow
Strategy - 溢出处理策略
- Pool
Error - 连接池特有错误
- QoS
- Rate
Limit Error - Rate
Limit Response Strategy - 限流响应策略
- Relation
- 模型间的关系描述
- Relation
Error - 关系操作错误类型
- Scheduler
Error - 调度器根级 re-export(供 core 内部 dogfood 使用)
- SqlStatement
Type - SQL statement type detected by the parser
- SqlToken
- SQL 令牌类型(简化 AST 分析用)。
- SqlValidation
Error - SQL validation errors
- Storage
Error - Storage
Provider - Storage
Wrapper - Tracing
Error - Value
- 数据库值类型
- WsError
Traits§
- Alert
Hook - 告警分发钩子。实现方可以将告警写入日志、发送到 Webhook、推送到 IM 等。
- Authorizer
- Cache
- Connection
- 数据库连接 trait
- Connection
Factory - 连接工厂 trait,用于创建新连接
- JobHandler
- 调度器根级 re-export(供 core 内部 dogfood 使用)
Handler invoked by the scheduler when a task’s cron expression matches
the current time. Implementations must be
Send + Syncbecause they may be invoked from a background thread. - Message
Queue - 消息队列统一抽象
- Model
- 所有 ORM 模型必须实现的核心 trait
- Model
Ext - 模型扩展 trait,提供额外功能
- Rate
Limiter - RateLimiter trait re-export(限流中间件核心 trait)
- Relation
Access ModelExt的关系访问扩展方法- Relation
Loader - 可存储已加载关系数据的模型 trait
- Scheduler
- 调度器根级 re-export(供 core 内部 dogfood 使用)
- Storage
- Tracer
- WebSocket
Handler
Functions§
- detect_
statement_ type - Detect the type of SQL statement
- validate
- Entry-level validation that runs all checks
- validate_
column_ name - Validate column name is a valid SQL identifier
- validate_
delete - Validate a SQL DELETE statement
- validate_
insert - Validate a SQL INSERT statement
- validate_
parameter_ count - Validate parameter count in prepared statements
- validate_
select - Validate a SQL SELECT statement
- validate_
sql - Validate any SQL statement by detecting its type and applying appropriate rules
- validate_
table_ name - Validate table name is a valid SQL identifier
- validate_
update - Validate a SQL UPDATE statement
- value_
to_ json - 将 Value 转换为 serde_json::Value(递归处理 Array)
Type Aliases§
- Validation
Result - Result type for SQL validation