Gremlin ORM
A lightweight, type-safe ORM for PostgreSQL in Rust, built on top of SQLx with derive macro support for common CRUD operations.
Features
- 🔒 Type-safe - Compile-time SQL query verification via SQLx
- 🚀 Async/await - Full async support with streaming capabilities
- 📝 Derive macros - Minimal boilerplate with
#[derive(Entity)] - 🐘 PostgreSQL optimized - Leverages PostgreSQL-specific features
- 🔄 CRUD operations - Insert, Update, Delete, and Stream entities
- 🏗️ Generated fields - Support for auto-increment IDs and computed columns
- 🗑️ Soft deletes - Mark records as deleted without removing them from the database
See the documentation on docs.rs
Quick Start
Add gremlin-orm and sqlx to your Cargo.toml:
[]
= { = "0.8.6", = ["postgres", "runtime-tokio"] }
= "0.1.0"
Usage
Define an Entity
use ;
use StreamExt;
Field-level Annotations
-
#[orm(pk)]: Marks the field as a primary key. Multiple fields can be marked as primary keys for composite keys. -
#[orm(generated)]: Indicates the field is auto-generated by the database (e.g., auto-increment or computed columns). Such fields are excluded from inserts and updates. -
#[orm(deref)]: Used for optional/reference types (e.g.,Option<T>,&str, etc.), allowing the macro to handle dereferencing when generating queries. -
#[orm(as_ref)]: Used for optional primitive types (e.g.,Option<i32>,Option<bool>), calling.as_ref()instead of.as_deref()when generating update queries. This is useful for optional primitive values that don't need dereferencing. -
#[orm(default)]: Allows the field to use a default value when inserting, by wrapping it inDefaultable<T>. -
#[orm(cast = "TYPE")]: Casts the field to the specified SQL type in generated queries. This is useful when you want to explicitly cast a column in SQL (e.g., for custom types or to resolve type mismatches).Example:
Basic Operations
async
License
This project is licensed under the GNU General Public License v3.0.