2025-07-26 00:28:20 +02:00
2025-07-25 21:53:24 +02:00
2025-07-28 00:18:58 +02:00
2025-03-30 11:21:50 +02:00
2025-03-30 11:21:50 +02:00
2025-07-26 00:28:20 +02:00
2025-07-26 15:01:44 +02:00
2025-07-26 00:28:20 +02:00
2025-07-26 00:28:20 +02:00
2025-07-26 00:28:20 +02:00
2025-07-25 21:53:24 +02:00
2025-07-25 22:13:45 +02:00
2025-07-25 22:13:45 +02:00

SkyORM

Warning

SkyORM is under very early development. Expect frequent breaking changes!

SkyORM is a light-weight ORM intended to be used in conjunction with sqlx.

Inspired by sqlx' compile-time checked queries, SkyORM lets you generate your Rust models directly from your database schema at compile time. To do so, first generate a schema in JSON format using SkyORM's CLI, like so:

sky-orm generate-schema -d postgresql://postgres:mypassword@localhost:5432/database_name

This will create a schema.json file containing relevant database information, such as tables, columns, types, and relations (for databases that support it). You can then automatically insert these models in your Rust code using the model! macro:

model! {
    // Table name. Any attributes added right here will be added to the
    // model struct.
    #[derive(Serialize, Deserialize)]
    "user",
    fields: {
        // By default, column names will be converted to snake case, i.e.
        // firstName will become first_name.
        // You can rename columns with the `->` token, this uses the column
        // name as it appears in the database:
        id -> user_id,
        firstName -> user_first_name,
        // Attributes can be added to struct fields, this uses the struct field name:
        #[serde(skip)]
        password,
        // Types can be overridden. E.g. imagine that account_type is stored as a
        // string in our DB, but we have an enum that implements `Decode`:
        account_type: UserAccountType,
        // All of these can be combined as well:
        #[serde(skip)]
        userRoleInProduct -> user_role: UserRoleType
    }
}

The model! macro will also automatically implement relations based on foreign-key constraints, if your database supports it. To find target entities, it will look in the super module, with the table name converted to snake_case, so it makes sense to ensure that all your models share the same parent module.

Description
Rust ORM to be used in tandem with sqlx.
Readme MIT 620 KiB
Languages
Rust 95.2%
Nix 4.8%