Crate bottle_orm

Crate bottle_orm 

Source
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 tokio and sqlx
  • 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 database::DatabaseBuilder;
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;
pub use pagination::Pagination;

Modules§

any_struct
Support for mapping arbitrary AnyRow results 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.
pagination
Pagination utilities for web framework integration.
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§

FromAnyRow
Re-export of the procedural macro for deriving FromRow for AnyRow and AnyImpl.
Model
Re-export of the procedural macro for deriving the Model trait.