ormkit-derive 0.2.0

Derive macros for ormkit - compile-time safe ORM with typed DSL, automatic relationships, and enterprise features
Documentation

ormkit-derive

Derive macros for the ormkit ORM library.

Installation

[dependencies]
ormkit = "0.1"
ormkit-derive = "0.1"

Derive Macros

Entity

The Entity derive macro automatically implements the Entity trait and generates an ActiveModel for your structs.

#[derive(ormkit::Entity)]
#[ormkit(table = "users")]
struct User {
    #[ormkit(id)]
    id: Uuid,
    email: String,
    name: String,
}

Attributes

  • #[ormkit(table = "table_name")] - Specifies the database table name
  • #[ormkit(id)] - Marks a field as the primary key

Generated Code

The derive macro generates:

  1. Entity trait implementation - Provides database metadata for the entity
  2. ActiveModel - Tracks field changes for efficient partial updates
  3. Table metadata - Column names, types, and constraints

Example

use ormkit::{Entity, ActiveModelTrait};
use ormkit::active_value::ActiveValue;

#[derive(ormkit::Entity, Debug, Clone)]
#[ormkit(table = "users")]
struct User {
    #[ormkit(id)]
    id: Uuid,
    email: String,
    name: String,
    created_at: chrono::DateTime<chrono::Utc>,
}

// Use the generated ActiveModel
let mut user = UserActiveModel::default();
user.email = ActiveValue::Set("user@example.com".to_string());
user.name = ActiveValue::Set("John Doe".to_string());

License

MIT OR Apache-2.0

See Also