Expand description
§grorm — A goroutine-native async ORM for Rust
grorm (GRoutines + ORM) is a database ORM built on top of gorust,
providing a goroutine-native async experience without tokio. It supports PostgreSQL, MySQL, and SQLite.
§Quick Start
use grorm::{ConnectionConfig, ConnectionPool, SqliteDriverFactory, QueryBuilder, Value};
use grorm::DeriveModel;
use gorust::runtime;
#[derive(Debug, DeriveModel)]
#[table = "users"]
struct User {
id: i64,
#[index]
name: String,
#[unique]
email: String,
age: i32,
}
#[runtime]
fn main() -> Result<(), grorm::Error> {
let config = ConnectionConfig::sqlite("test.db");
let pool = ConnectionPool::new(SqliteDriverFactory, config, 4);
let mut conn = pool.get()?;
let mut qb = QueryBuilder::<User>::new(conn.driver_mut());
// Create table with indexes
qb.create_table()?;
// Insert
let user = User { id: 0, name: "Alice".into(), email: "alice@x.com".into(), age: 30 };
qb.insert(&user)?;
// Chainable query
let users = qb.where_eq("name", Value::from("Alice")).find()?;
println!("{:?}", users);
Ok(())
}§Features
- Multi-database: PostgreSQL, MySQL, SQLite
- Chainable API:
where_eq().limit().offset().order().find() - Transactions:
Transaction::begin()with auto-rollback on drop - Auto table creation:
create_table()generates DDL from model - Index & unique constraints:
#[index],#[unique],#[unique_index = "name"] - JOIN support:
left_join(),inner_join(),right_join() - IN queries:
where_in("name", vec![...]) - Connection pooling: gorust channel-based pool
- Derive macros:
#[derive(DeriveModel)]auto-generates Model trait
Re-exports§
pub use driver::ConnectionConfig;pub use driver::DatabaseDriver;pub use driver::DatabaseType;pub use driver::DriverFactory;pub use driver::DriverRegistry;pub use driver::MysqlDriver;pub use driver::MysqlDriverFactory;pub use driver::PostgresDriver;pub use driver::PostgresDriverFactory;pub use driver::SqliteDriver;pub use driver::SqliteDriverFactory;pub use error::Error;pub use error::Result;pub use orm::ColumnInfo;pub use orm::JoinClause;pub use orm::JoinType;pub use orm::Model;pub use orm::QueryBuilder;pub use orm::Transaction;pub use pool::ConnectionPool;pub use types::FromSql;pub use types::Id;pub use types::ToSql;pub use types::Value;