#sqlite #orm #sql #macro-derive

geekorm

A simple and easy to use ORM for SQLite databases

13 releases

new 0.3.1 May 16, 2024
0.3.0 May 15, 2024
0.2.8 May 15, 2024
0.2.4 Apr 30, 2024
0.1.1 Apr 18, 2024

#719 in Database interfaces

Download history 60/week @ 2024-04-04 75/week @ 2024-04-11 244/week @ 2024-04-18 747/week @ 2024-04-25 288/week @ 2024-05-02

1,414 downloads per month
Used in geekorm-cli

MIT license

190KB
2.5K SLoC

GeekORM

GitHub Crates.io Version Crates.io Downloads (recent) GitHub Stars GitHub Issues Licence

Overview

GeekORM is a simple Object Relation Mapper for empowering your Rust development.

✨ Features

  • Focus on simplicity
  • Rely on Derive Macros to generate code for your structs
    • Using GeekTable
  • Dynamically build queries
    • Select, Create, Update, and Insert queries
  • Extensive crate features
  • Field Attribute Helpers
    • foreign_key: Set the foreign key for a join
    • rand: Generate random strings (set lenght, set prefix, set enviroment)
    • hash or password: Generate secure Hashes of passwords (set algorithm)
  • Support for Backends
  • Documentation

📦 Usage

You can install the library from crates.io:

cargo add geekorm

Manual - GitHub

cargo install --git https://github.com/42ByteLabs/geekorm

🏃 Getting Started

Once you have installed geekorm, you can start using the derive macros like the following:

use geekorm::prelude::*;
use geekorm::{QueryOrder, PrimaryKeyInteger};

#[derive(Debug, Clone, GeekTable)]
struct Users {
   id: PrimaryKeyInteger,
   username: String,
   email: String,
   age: i32,
   postcode: Option<String>,
}

// Use the `create` method to build a CREATE TABLE query
let create_table = Users::create().build()
    .expect("Failed to build create table query");
println!("Create Table Query: {}", create_table);

// Use the `select` method to build a SELECT query along with different conditions
// and ordering
let select_user = Users::select()
    .where_eq("username", "geekmasher")
    .and()
    .where_gt("age", 42)
    .order_by("age", QueryOrder::Asc)
    .limit(10)
    .build()
    .expect("Failed to build query");

🏄 Create Features

There are a number of opt-in features supported by GeekORM. Features can be added either using cargo add geekorm -F all or added them directly in your Cargo.toml file.

  • all: Enable all the major stable features
  • new: Generate Table::new(...) functions
  • helpers: Generate a number of helper functions
    • Select Table::select_by_primary_key()
    • Select column Table::select_by_{field}()
  • rand: Support Generating random strings
  • hash: Support Generating password hashes
  • Backends
    • libsql: Add LibSQL backend support

🧑‍🤝‍🧑 Maintainers / Contributors

Mathew Payne
Mathew Payne

💻 👀
Cale
Cale

🎨

🦸 Support

Please create GitHub Issues if there are bugs or feature requests.

This project uses Semantic Versioning (v2) and with major releases, breaking changes will occur.

📓 License

This project is licensed under the terms of the MIT open source license. Please refer to MIT for the full terms.

Dependencies

~1.7–3MB
~61K SLoC