ferroquent
A faithful port of Laravel's Eloquent ORM to Rust.
Rust has excellent query builders and entity-first ORMs, but nothing with Eloquent's ActiveRecord
ergonomics. Ferroquent brings that feel with models, relations, eager loading, existence queries,
scopes, soft deletes, casts, observers, factories, a schema builder, and migrations. It runs on
MySQL, MariaDB, and PostgreSQL through sqlx, behind a driver seam so other backends can be added
without touching the core.
This is the facade crate: it re-exports the prelude, the #[derive(Model)] macro, and
Ferroquent::boot. Add it and start defining models.
[dependencies]
ferroquent = "0.0.1"
tokio = { version = "1", features = ["full"] }
use ferroquent::prelude::*;
#[derive(Model, Clone, Debug, Default)]
#[ferroquent(soft_deletes)]
struct User {
id: u64,
#[ferroquent(fillable)] name: String,
#[ferroquent(fillable)] email: String,
#[ferroquent(fillable)] votes: i32,
created_at: Option<chrono::NaiveDateTime>,
updated_at: Option<chrono::NaiveDateTime>,
deleted_at: Option<chrono::NaiveDateTime>,
posts: HasMany<Post>,
state: ModelState<User>,
}
# async fn demo() -> ferroquent::core::error::Result<()> {
Ferroquent::boot(ConnectionConfig::from_url("mysql://root:secret@127.0.0.1/app")?)?;
let conn = Ferroquent::connection(None).await?;
let db = conn.as_ref();
let mut user = User::create(db, record([
("name", Value::Str("Taylor".into())),
("email", Value::Str("taylor@example.com".into())),
("votes", Value::Int(10)),
])).await?;
user.votes = 11;
user.save(db).await?;
let mut q = User::query();
q.where_("votes", ">", 8).with(["posts"]).order_by_desc("votes");
let active = q.get(db).await?; # Ok(()) }
See the repository for the full feature list, the
workspace layout, running the live-database test suite, and the documented deviations from Eloquent.
License
MIT