Crate premix_orm

Crate premix_orm 

Source
Expand description

§Premix ORM

“Write Rust, Run Optimized SQL.”

Premix is a zero-overhead, type-safe ORM for Rust. It generates SQL at compile time with macros and executes via sqlx.

§Key Features

  • Auto-sync schema from models.
  • Compile-time SQL generation (no runtime reflection).
  • Application-level joins with batched WHERE IN queries.
  • SQLite, Postgres, and MySQL support via sqlx.

§Quick Start

use premix_orm::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Model, Debug, Serialize, Deserialize)]
struct User {
    id: i32,
    name: String,
}

let pool = Premix::smart_sqlite_pool("sqlite::memory:").await?;
premix_orm::Premix::sync::<premix_orm::sqlx::Sqlite, User>(&pool).await?;

let mut user = User { id: 0, name: "Alice".to_string() };
user.save(&pool).await?;

§Relations and Eager Loading

use premix_orm::prelude::*;

#[derive(Model)]
struct User {
    id: i32,
    name: String,

    #[has_many(Post)]
    #[premix(ignore)]
    posts: Option<Vec<Post>>,
}

#[derive(Model)]
#[belongs_to(User)]
struct Post {
    id: i32,
    user_id: i32,
    title: String,
}

let _users = User::find_in_pool(&pool).include("posts").all().await?;

§Bulk Operations

use premix_orm::prelude::*;
use serde_json::json;

#[derive(Model)]
struct User {
    id: i32,
    status: String,
}

let _updated = User::find_in_pool(&pool)
    .filter_eq("status", "inactive")
    .update(json!({ "status": "active" }))
    .await?;

§Installation

[dependencies]
premix-orm = "1.0.6-alpha"

§Book

A longer-form guide lives in orm-book/ at the repository root. It covers models, queries, relations, migrations, transactions, and limitations.

Modules§

migrator
prelude
schema
sqlx
The async SQL toolkit for Rust, built with ❤️ by the LaunchBadge team.
test_utils
tracing
A scoped, structured logging and diagnostics system.

Macros§

schema_models

Structs§

ColumnDiff
ColumnNullabilityDiff
ColumnPrimaryKeyDiff
ColumnTypeDiff
Migration
Migrator
MockDatabase
Lightweight test helper for constructing a dedicated pool.
Premix
QueryBuilder
RawQuery
SchemaColumn
SchemaDiff
SchemaForeignKey
SchemaIndex
SchemaTable
ValidationError

Enums§

Executor
RuntimeProfile
UpdateResult

Traits§

IntoExecutor
Model
ModelHooks
ModelSchema
ModelValidation
SqlDialect

Functions§

diff_postgres_schema
diff_sqlite_schema
format_schema_diff_summary
introspect_postgres_schema
introspect_sqlite_schema
postgres_migration_sql
sqlite_migration_sql
with_test_transaction
Run an async test block inside a transaction that is always rolled back.

Derive Macros§

Model