che-orm 0.3.3

Typed SQLite and PostgreSQL ORM for che-rest applications
Documentation
# Compile-Tested API Examples

The complete source for these examples is compiled as an external consumer in
[`tests/public_api_examples.rs`](../../tests/public_api_examples.rs). This keeps
the documentation aligned with the public derive and query APIs.

## Models and Relations

```rust
use che_orm::{DbEnum, Model};

#[derive(Debug, Clone, Copy, DbEnum)]
enum TaskStatus {
    Draft,
    #[db_enum(rename = "in_progress")]
    InProgress,
}

#[derive(Debug, Model)]
#[orm(table = "example_users")]
struct User {
    #[orm(primary_key)]
    id: i64,
    email: String,
}

#[derive(Debug, Model)]
#[orm(table = "example_tasks")]
struct Task {
    #[orm(primary_key)]
    id: i64,
    #[orm(foreign_key = User, on_delete = "set null")]
    assignee_id: Option<i64>,
    status: TaskStatus,
}
```

`Task::ASSIGNEE` is a typed relation descriptor. It supports `select_related`,
and its `reverse()` method represents the reverse relation. An optional foreign
key produces `WithOptionalOne` when loaded through `select_related`.

## Serializer Metadata

```rust
use che_orm::ModelSerializer;

#[derive(ModelSerializer)]
#[serializer(model = User)]
struct UserSerializer {
    #[serializer(read_only)]
    id: i64,
    email: String,
}
```

For nested relation serializers, use the generated relation marker and load the
relation before serialization. See [Models and schema](models.md) for a
complete `prefetch_related` example.

## Query Fields

```rust
let query = User::query()
    .filter(User::EMAIL.eq("alice@example.test"))
    .order_by(User::ID.asc())
    .limit(20);
```

Execute a queryset with `&Database`, for example `query.all(&database).await?`.
Filter values are parameterized; table and column identifiers are generated by
the model derive.