Crate lume

Crate lume 

Source
Expand description

§Lume

A type-safe, ergonomic schema builder and ORM for SQL databases, inspired by Drizzle ORM.

§Features

  • 🚀 Type-safe: Compile-time type checking for all database operations
  • 🎯 Ergonomic: Clean, intuitive API inspired by modern ORMs
  • Performance: Zero-cost abstractions with minimal runtime overhead
  • 🔧 Flexible: Support for various column constraints and SQL types
  • 🛡️ Safe: Prevents SQL injection and runtime type errors
  • 📦 Lightweight: Minimal dependencies, maximum functionality

§Quick Start

use lume::define_schema;
use lume::schema::{Schema, ColumnInfo, Value};
use lume::database::Database;

// Define your database schema
define_schema! {
    Users {
        id: i32 [primary_key().not_null()],
        username: String [not_null()],
        email: String,
        age: i32,
        is_active: bool [default_value(true)],
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to your MySQL/Postgres database
    let db = Database::connect("mysql://user:password@localhost/database").await?;
     
    // Type-safe queries
    let users = db
        .query::<Users, SelectUsers>()
        .filter(lume::filter::Filter::eq_value("username", Value::String("john_doe".to_string())))
        .execute()
        .await?;
     
    for user in users {
        let username: Option<String> = user.get(Users::username());
        println!("User: {}", username.unwrap_or_default());
    }
     
    Ok(())
}

§Supported Database Types

  • StringVARCHAR(255)
  • i32INTEGER
  • i64BIGINT
  • f32FLOAT
  • f64DOUBLE
  • boolBOOLEAN

§Column Constraints

  • primary_key() - Sets the column as primary key
  • not_null() - Makes the column NOT NULL
  • unique() - Adds a UNIQUE constraint
  • indexed() - Creates an index on the column
  • default_value(value) - Sets a default value

Modules§

database
Database connection and management functionality
filter
Query filtering and condition building
operations
Database operations (queries, inserts, etc.)
row
Row abstraction for type-safe data access
schema
Schema definition and column management
table
Table registry and definition management

Macros§

__lume_option_type
Helper macro: decides field type as Option<T> if default_value(...) or auto_increment() is present in the column args; otherwise keeps it as T.
define_schema
Defines a database schema with type-safe columns and constraints.
enum_to_sql
Macro to generate SQL string conversions for enums used as custom SQL column types.