Expand description
§Bottle ORM
Bottle ORM is a lightweight, async ORM for Rust built on top of sqlx. It is designed to be simple, efficient, and easy to use, providing a fluent Query Builder and automatic schema migrations.
§Features
- Async & Non-blocking: Built on
tokioandsqlx - Multi-Driver Support: Compatible with PostgreSQL, MySQL, and SQLite (via
sqlx::Any) - Macro-based Models: Define your schema using standard Rust structs with
#[derive(Model)] - Fluent Query Builder: Chainable methods for filtering, selecting, pagination, and sorting
- Auto-Migration: Automatically creates tables and foreign key constraints based on your structs
- UUID Support: Full support for UUID versions 1 through 7
§Quick Start Example
ⓘ
use bottle_orm::{Database, Model};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
#[derive(Model, Debug, Clone, Serialize, Deserialize, FromRow)]
struct User {
#[orm(primary_key)]
id: i32,
#[orm(size = 50, unique)]
username: String,
age: i32,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = Database::connect("sqlite::memory:").await?;
db.migrator()
.register::<User>()
.run()
.await?;
let users: Vec<User> = db.model::<User>()
.filter("age", ">=", 18)
.scan()
.await?;
Ok(())
}Re-exports§
pub use database::Database;pub use model::ColumnInfo;pub use model::Model;pub use any_struct::AnyImpl;pub use any_struct::AnyInfo;pub use transaction::Transaction;pub use query_builder::QueryBuilder;pub use migration::Migrator;pub use errors::Error;
Modules§
- any_
struct - Support for mapping arbitrary
AnyRowresults to structs. - database
- Database connection and driver management.
- errors
- Error types and handling.
- migration
- Schema migration management.
- model
- Core Model trait and column metadata structures.
- query_
builder - Fluent query builder for constructing SQL queries.
- temporal
- Temporal type conversion and handling.
- transaction
- Transaction Module
- value_
binding - Value binding utilities for SQL queries.
Derive Macros§
- From
AnyRow - Re-export of the procedural macro for deriving
FromRowforAnyRowandAnyImpl. - Model
- Re-export of the procedural macro for deriving the
Modeltrait.