Expand description
che-orm — экспериментальная типизированная ORM для Rust.
Backend выбирается feature sqlite или postgres: Database предоставляет async
pool и high-level CRUD/query facade, а Model derive генерирует metadata,
row decoding и insert values. SQL можно также использовать отдельно через
SqlCompiler.
Основной рабочий сценарий для backend sqlite. create_table подходит для
тестов и локальных экспериментов; для постоянной схемы используйте миграции.
use che_orm::{Database, Model};
#[derive(Debug, Model)]
#[orm(table = "users")]
struct User {
#[orm(primary_key)]
id: i64,
name: String,
}
let database = Database::connect_in_memory().await?;
database.create_table::<User>().await?;
let user = database
.create::<User>()
.set(User::NAME, "Alice")
.execute()
.await?;
let loaded = database.get::<User>(user.id).await?;
assert_eq!(loaded.unwrap().name, "Alice");Fixed string choices use DbEnum. It owns the JSON and database value,
so a variant has one canonical representation everywhere:
use che_orm::DbEnum;
#[derive(Debug, Clone, Copy, DbEnum)]
enum TaskStatus {
Draft,
#[db_enum(rename = "in_progress")]
InProgress,
}
assert_eq!(TaskStatus::InProgress.as_str(), "in_progress");
assert_eq!(
che_orm::serde_json::to_string(&TaskStatus::InProgress).unwrap(),
"\"in_progress\"",
);Do not derive serde::Serialize or serde::Deserialize for a DbEnum;
the derive generates both implementations.
Re-exports§
pub use rusqlite;pub use serde;pub use serde_json;pub use time;pub use migration::*;
Modules§
Structs§
- AppRegistry
- Registry that combines schemas from multiple application modules.
- Assignment
- Belongs
To - A typed forward foreign-key relation from one model to another.
- Bound
Query - A query bound to the database that created it.
- Column
Ref - Column
Schema - Metadata for one table column.
- Compiled
Query - SQL text and ordered bound parameters.
- Compiled
Schema - Table DDL plus separately executable indexes.
- Create
Builder - Create
Table Ast - AST node for a
CREATE TABLEstatement. - Create
Table Query - Builder for a model’s
CREATE TABLEstatement. - Database
- Async database using the backend selected by the crate feature.
- Database
Query - Delete
Ast - Delete
Query - Execute
Result - Foreign
Key - Foreign key metadata attached to a column.
- HasMany
- A typed reverse foreign-key relation from one model to many related models.
- Image
Field - A relative storage key for an image. The bytes live in a media backend,
not in the database;
che-restmanages uploads and URLs. - Insert
Ast - Insert
Query - Insert
Value - JoinAst
- Joined
Field - Json
Field - JSON stored as SQL TEXT and serialized as a JSON value, never as an escaped string.
- Loaded
- Loaded
Many - Loaded
One - Model
Field - A typed reference to one model column.
- Model
Write Result - Multi
Prefetch Related Query - Multi
Select Related Query - Nested
Prefetch Plan - Nested
Prefetch Query - Optional
Rfc3339 Timestamp - Serializes an optional timestamp in RFC 3339 when it has a value.
- OrderBy
- Postgres
Dialect - Prefetch
Related Query - Rfc3339
Timestamp - Serializes a timestamp in the RFC 3339 format used by JSON API clients.
- Row
- An owned row with the same decoding interface for either backend.
- Schema
Set - A collection of model schemas exported as one SQL schema.
- Select
Ast - Select
Query - Select
Related Query - Serializer
Field - SqlCompiler
- Sqlite
Dialect - Sync
Field - Stable protocol name mapped to a model-controlled SQL column.
- Sync
Registration - Runtime-independent registration consumed by che-sync.
- Table
Ref - Table
Schema - Complete model table metadata used for DDL generation.
- Transaction
- ORM operations pinned to one transaction connection on either backend.
- Transaction
Create Builder - Transaction
Query - Transaction
Update Builder - Update
Ast - Update
Builder - Update
Query - Uuid
- A Universally Unique Identifier (UUID).
- Validation
Errors - With
Many - WithOne
- With
Optional One
Enums§
- Column
Type - SQL column types supported by the schema compiler.
- Compare
Op - Constraint
Kind - Database
Value - Values bound to SQL placeholders.
- Decode
Error - Expr
- Boolean and comparison expression tree used by query builders.
- Isolation
Level - Join
Type - Model
Role - Role of a synchronized model in a particular database.
- Order
Direction - OrmError
- Patch
Field - A JSON patch value.
Missingmeans that the property was not sent;Value(None)represents an explicit JSON null. - Query
Ast - Query
Build Error - Errors detected while finalizing a query builder.
- Schema
Error - Errors found in model-generated schema metadata.
- Validated
Write - Write
Mode
Traits§
- AppConfig
- Application-level model registration, similar to a Django app config.
- Column
Type Of - Maps a Rust field type to a SQL column type.
- DbEnum
- A string-backed enum that can be stored in a database column.
- Foreign
KeyValue - Extracts the owner key from a required or nullable foreign-key field.
- From
Database Value - Converts a materialized database value into a model field.
- Model
- Trait implemented by
#[derive(Model)]for ORM models. - Model
Runtime - Transactional extension point for registered model writes. Implementations use raw transaction methods internally to avoid recursively capturing writes.
- Model
Serializer - Converts a materialized ORM model into an API representation.
- Model
Write Serializer - Prefetch
Relation - Primary
Key - Supported model keys, including their automatic INSERT value.
- Query
Value - Relation
Source - Identifies the actual foreign-key column behind a serializer relation.
- SqlDialect
- Sync
Model - Shared model definition. Its client/server role belongs to registration.
Functions§
- deserialize_
optional_ rfc3339 - Deserializes an optional RFC 3339 timestamp sent by JSON API clients.
- deserialize_
patch_ optional_ rfc3339 - Deserializes an optional RFC 3339 timestamp while preserving patch-field presence.
- deserialize_
patch_ rfc3339 - Deserializes an RFC 3339 timestamp while preserving patch-field presence.
- deserialize_
rfc3339 - Deserializes an RFC 3339 timestamp sent by JSON API clients.
- sync_
migration_ operations - Infrastructure tables shared by all registrations of a database role.
- sync_
migration_ operations_ for_ role - Explicit role variant, also useful for an empty legacy registry.