{"id":31750557,"url":"https://github.com/guru901/lume","last_synced_at":"2026-01-20T17:53:43.401Z","repository":{"id":316412655,"uuid":"1038549904","full_name":"Guru901/Lume","owner":"Guru901","description":"A simple and intuitive Query Builder inspired by Drizzle","archived":false,"fork":false,"pushed_at":"2025-10-01T17:17:54.000Z","size":180,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-01T19:17:26.182Z","etag":null,"topics":["database","orm","query-builder","schema-builder"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/lume","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Guru901.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-15T12:10:42.000Z","updated_at":"2025-10-01T17:17:59.000Z","dependencies_parsed_at":"2025-09-24T13:27:25.713Z","dependency_job_id":null,"html_url":"https://github.com/Guru901/Lume","commit_stats":null,"previous_names":["guru901/lume"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Guru901/Lume","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guru901%2FLume","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guru901%2FLume/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guru901%2FLume/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guru901%2FLume/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Guru901","download_url":"https://codeload.github.com/Guru901/Lume/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guru901%2FLume/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001642,"owners_count":26083147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","orm","query-builder","schema-builder"],"created_at":"2025-10-09T15:53:14.755Z","updated_at":"2025-10-09T15:53:15.958Z","avatar_url":"https://github.com/Guru901.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lume\n\nA type-safe, ergonomic schema builder and ORM for SQL databases, inspired by Drizzle ORM.\n\n[![Crates.io](https://img.shields.io/crates/v/lume)](https://crates.io/crates/lume)\n[![Documentation](https://img.shields.io/docsrs/lume)](https://docs.rs/lume)\n[![License](https://img.shields.io/crates/l/lume)](LICENSE)\n\n## Features\n\n- 🚀 **Type-safe**: Compile-time type checking for all database operations\n- 🎯 **Ergonomic**: Clean, intuitive API inspired by modern ORMs\n- ⚡ **Performance**: Zero-cost abstractions with minimal runtime overhead\n- 🔧 **Flexible**: Support for various column constraints and SQL types\n- 🛡️ **Safe**: Parameterized queries by default to prevent SQL injection\n- 📦 **Lightweight**: Minimal dependencies, maximum functionality\n\n## Quick Start\n\nAdd Lume to your `Cargo.toml`:\n\n```toml\n[dependencies]\nlume = \"0.4\"\ntokio = { version = \"1.0\", features = [\"macros\", \"rt-multi-thread\"] }\n```\n\n### Basic Usage\n\n```rust\nuse lume::{\n    database::Database,\n    define_schema,\n    filter::eq_value,\n    schema::{ColumnInfo, Schema},\n};\n\n// Define your database schema\ndefine_schema! {\n    Users {\n        id: i32 [primary_key().not_null()],\n        username: String [not_null()],\n        email: String,\n        age: i32,\n        is_active: bool [default_value(true)],\n        created_at: i64 [not_null()],\n    }\n\n    Posts {\n        id: i32 [primary_key().not_null()],\n        title: String [not_null()],\n        content: String,\n        created_at: i64 [not_null()],\n    }\n}\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Connect to your MySQL database\n    let db = Database::connect(\"mysql://user:password@localhost/database\").await?;\n\n    // Create tables (if they don't exist)\n    db.register_table::\u003cUsers\u003e().await?;\n    db.register_table::\u003cPosts\u003e().await?;\n\n    // Type-safe queries\n    let users = db\n        .query::\u003cUsers, SelectUsers\u003e()\n        .select(SelectUsers::selected().age().username())\n        .filter(eq_value(Users::username(), \"john_doe\"))\n        .execute()\n        .await?;\n\n    for user in users {\n        let username: Option\u003cString\u003e = user.get(Users::username());\n        let age: Option\u003ci32\u003e = user.get(Users::age());\n        println!(\n            \"User: {} (age: {})\",\n            username.unwrap_or_default(),\n            age.unwrap_or(0)\n        );\n    }\n\n    db.insert(Users {\n        id: 0,\n        age: 25,\n        username: \"john_doe\".to_string(),\n        email: \"john.doe@example.com\".to_string(),\n        is_active: true,\n        created_at: 1677721600,\n    })\n    .execute()\n    .await\n    .unwrap();\n\n    // Raw SQL (bypasses type-safe query builder; ensure your SQL matches the schema)\n    let adult_users = db\n        .sql::\u003cUsers\u003e(\"SELECT * FROM Users WHERE age \u003e 18\")\n        .await\n        .unwrap();\n\n    for user in adult_users {\n        let username: Option\u003cString\u003e = user.get(Users::username());\n        println!(\"Adult user: {}\", username.unwrap_or_default());\n    }\n\n    Ok(())\n}\n```\n\n## Schema Definition\n\nLume provides a powerful macro system for defining database schemas:\n\n```rust\ndefine_schema! {\n    Product {\n        id: i32 [primary_key().not_null()],\n        name: String [not_null().unique()],\n        description: String,\n        price: f64 [not_null()],\n        stock: i32 [default_value(0)],\n        category_id: i32 [not_null().indexed()],\n        created_at: i64 [not_null()],\n        updated_at: i64 [not_null()],\n    }\n}\n```\n\n### Supported Types\n\n- `String` → `VARCHAR(255)`\n- `i32` → `INTEGER`\n- `i64` → `BIGINT`\n- `f32` → `FLOAT`\n- `f64` → `DOUBLE`\n- `bool` → `BOOLEAN`\n\n### Column Constraints\n\n- `primary_key()` - Sets the column as primary key\n- `not_null()` - Makes the column NOT NULL\n- `unique()` - Adds a UNIQUE constraint\n- `indexed()` - Creates an index on the column\n- `default_value(value)` - Sets a default value\n\n## Type-Safe Queries\n\n```rust\nuse lume::filter::{eq_value, lt};\n\n// Filter by equality\nlet active_users = db\n    .query::\u003cUsers, SelectUsers\u003e()\n    .filter(eq_value(Users::is_active(), true))\n    .execute()\n    .await?;\n\n// Multiple filters\nlet young_active_users = db\n    .query::\u003cUsers, SelectUsers\u003e()\n    .filter(eq_value(Users::is_active(), true))\n    .filter(lt(Users::age(), 25))\n    .execute()\n    .await?;\n\n// Access row data type-safely\nfor user in young_active_users {\n    let id: Option\u003ci32\u003e = user.get(Users::id());\n    let username: Option\u003cString\u003e = user.get(Users::username());\n    let email: Option\u003cString\u003e = user.get(Users::email());\n\n    println!(\n        \"User {}: {} ({})\",\n        id.unwrap_or(0),\n        username.unwrap_or_default(),\n        email.unwrap_or_default()\n    );\n}\n```\n\n### Joins\n\n```rust\nuse lume::filter::eq_column;\n\n// Example joining two tables using a LEFT JOIN\n// Here we assume a schema with `Author` and `Book` where `Book.author_id` references `Author.id`\nlet authors_with_books = db\n    .query::\u003cAuthor, SelectAuthor\u003e()\n    .select(SelectAuthor::selected().name())\n    .left_join::\u003cBook, QueryBook\u003e(\n        eq_column(Author::id(), Book::author_id()),\n        QueryBook { title: true, ..Default::default() },\n    )\n    .execute()\n    .await?;\n\n// INNER JOIN (returns only matching rows)\nlet authors_and_books = db\n    .query::\u003cAuthor, SelectAuthor\u003e()\n    .inner_join::\u003cBook, QueryBook\u003e(\n        eq_column(Author::id(), Book::author_id()),\n        QueryBook { title: true, ..Default::default() },\n    )\n    .execute()\n    .await?;\n\n// RIGHT JOIN (when supported by your database and use-case)\nlet right_joined = db\n    .query::\u003cAuthor, SelectAuthor\u003e()\n    .right_join::\u003cBook, QueryBook\u003e(\n        eq_column(Author::id(), Book::author_id()),\n        QueryBook { title: true, ..Default::default() },\n    )\n    .execute()\n    .await?;\n```\n\n### Complex Filters\n\n```rust\nuse lume::filter::{and, or, eq_value, gt_value, lt_value, in_values};\n\n// Assuming your `Users` schema includes the referenced columns\nlet date_threshold = 1_696_000_000i64; // example UNIX timestamp\n\nlet users = db\n    .query::\u003cUsers, SelectUsers\u003e()\n    .filter(or(\n        and(\n            eq_value(Users::status(), \"active\"),\n            or(\n                eq_value(Users::role(), \"admin\"),\n                and(\n                    eq_value(Users::role(), \"user\"),\n                    gt_value(Users::created_at(), date_threshold),\n                ),\n            ),\n        ),\n        and(\n            eq_value(Users::status(), \"pending\"),\n            lt_value(Users::failed_attempts(), 3),\n        ),\n        in_values(Users::username(), vec![\"bob\", \"alice\", \"charlie\"]),\n    ))\n    .execute()\n    .await?;\n```\n\n## Advanced Features\n\n### Custom Default Values\n\n```rust\ndefine_schema! {\n    Settings {\n        id: i32 [primary_key().not_null()],\n        theme: String [default_value(\"dark\".to_string())],\n        notifications: bool [default_value(true)],\n        max_connections: i32 [default_value(10)],\n    }\n}\n```\n\n### Table Relationships\n\n```rust\ndefine_schema! {\n    Author {\n        id: i32 [primary_key().not_null()],\n        name: String [not_null()],\n        email: String [not_null().unique()],\n    }\n\n    Book {\n        id: i32 [primary_key().not_null()],\n        title: String [not_null()],\n        author_id: i32 [not_null()], // References Author.id\n        published_year: i32,\n        isbn: String [unique()],\n    }\n}\n```\n\n## Error Handling\n\nLume provides comprehensive error handling:\n\n```rust\nmatch db.query::\u003cUsers, SelectUsers\u003e().execute().await {\n    Ok(users) =\u003e println!(\"Found {} users\", users.len()),\n    Err(e) =\u003e eprintln!(\"Database error: {}\", e),\n}\n```\n\n### Security\n\n- The query builder emits parameterized SQL and binds values with the driver to mitigate SQL injection.\n- The `sql::\u003cT\u003e(...)` escape hatch accepts raw SQL; use it carefully, as you are responsible for safety and correctness.\n\n## Testing\n\nLume includes comprehensive unit tests:\n\n```bash\ncargo test\n```\n\nRun specific test categories:\n\n```bash\ncargo test schema    # Schema definition tests\ncargo test row       # Row manipulation tests\ncargo test value     # Value conversion tests\ncargo test registry  # Table registry tests\n```\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines and submit pull requests for any improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for a detailed list of changes and improvements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguru901%2Flume","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguru901%2Flume","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguru901%2Flume/lists"}