# che-orm
`che-orm` is an experimental typed ORM for Rust. Its current runtime backend is
SQLite through `deadpool-sqlite`; models are decoded from rows generated by
procedural macros.
## Status
SQLite has an async pool, CRUD facade, transactions, relations, serializers,
and compiled migrations. The PostgreSQL dialect can compile SQL and DDL, but
does not yet provide a connection pool or executor.
## Quick Start
```toml
[dependencies]
che-orm = "0.2"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
time = { version = "0.3", features = ["formatting", "parsing"] }
```
```rust
use che_orm::{Database, Model};
use time::OffsetDateTime;
#[derive(Debug, Model)]
#[orm(table = "users")]
struct User {
#[orm(primary_key)]
id: i64,
#[orm(unique)]
email: String,
name: String,
#[orm(auto_now_add)]
created_at: OffsetDateTime,
#[orm(auto_now)]
updated_at: OffsetDateTime,
}
#[tokio::main]
async fn main() -> Result<(), che_orm::OrmError> {
let database = Database::connect("app.db")?;
database.create_table::<User>().await?;
let user = database
.create::<User>()
.set(User::EMAIL, "alice@example.test")
.set(User::NAME, "Alice")
.execute()
.await?;
let loaded = database.get::<User>(user.id).await?;
println!("{loaded:?}");
Ok(())
}
```
`create_table` is suitable for tests and local experiments. Use compiled
migrations for persistent application schemas.
## ImageField
Use `Option<ImageField>` when a record can have an image:
```rust
use che_orm::{ImageField, Model};
#[derive(Debug, Model)]
#[orm(table = "boards")]
struct Board {
#[orm(primary_key)]
id: i64,
preview: Option<ImageField>,
}
```
The nullable SQLite `TEXT` column stores a relative key such as
`board-previews/a1b2.png`, **not** image bytes, an absolute filesystem path, or
the browser URL. `che-orm` reads and writes this key; `che-rest::media` handles
uploads, validation, storage and serving files. Image fields are read-only in
JSON writes. `ImageField::new(...)` only wraps a trusted string: it does **not**
validate or create a file.
See the [step-by-step ImageField guide](docs/en/image-field.md) for the complete
model, ViewSet, JSON response, URL, deletion and migration workflow.
The repository migration CLI is an example application command:
```bash
cargo run -p che-orm-examples --bin manage -- schema
```
## Documentation
- [English guides](docs/en/README.md)
- [API examples](docs/en/api-examples.md)
- [Russian documentation](README.md)
- [Contributing](CONTRIBUTING.md)
- [Security policy](SECURITY.md)
- [Release checklist](docs/release-checklist.md)
## Verification
```bash
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo test -p che-orm --no-default-features --features postgres
cargo doc --workspace --no-deps
```