Expand description
§gremlin-orm
This crate provides a lightweight, type-safe ORM for PostgreSQL in Rust, focusing on minimal boilerplate and compile-time query safety.
§Example
use gremlin_orm::Entity;
#[derive(Entity, sqlx::FromRow)]
#[orm(table = "public.artist")]
struct Artist {
#[orm(pk, generated)]
id: i32,
name: String,
#[orm(generated)]
slug: String,
}§Annotations
The #[orm(...)] attribute supports both struct-level and field-level annotations to
control code generation and database mapping.
§Struct-level Annotations
#[orm(table = "schema.table")]: Specifies the database table for the entity.
§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(default)]: Allows the field to use a default value when inserting, by wrapping it inDefaultable<T>.
§Traits Overview
§InsertableEntity
For types that can be inserted into the database. An “Insertable” struct is generated for each entity, containing only the fields that should be provided on insert.
Field annotated with the default annotation are wrappedin Defaultable. Indicating if the
default value should be used, or the provided one
§FetchableEntity
For types that can be fetched by primary key(s) from the database. A “Pk” struct is generated for each entity, containing only the primary key fields.
§StreamableEntity
For types that can be streamed (selected) from the database. This trait is implemented for the entity struct, allowing you to stream all rows from the table.
§UpdatableEntity
For types that can be updated in the database. An “Updatable” struct is generated for each entity, containing the primary key(s) and updatable fields.
§DeletableEntity
For types that can be deleted from the database. This trait is implemented for the entity struct, allowing you to delete a row by its primary key(s).
Enums§
- Defaultable
- Used for inserting values, use either the default or the provided value
Traits§
- Deletable
Entity - Trait for types that can be deleted from the database. This trait is implemented for the entity struct, allowing you to delete a row by its primary key(s).
- Fetchable
Entity - Trait for types that can be fetched by primary key(s) from the database. A “Pk” struct is generated for each entity, containing only the primary key fields.
- Insertable
Entity - Trait for types that can be inserted into the database. An “Insertable” struct is generated for each entity, containing only the fields that should be provided on insert.
- Stream
- A stream of values produced asynchronously.
- Streamable
Entity - Trait for types that can be streamed (selected) from the database. This trait is implemented for the entity struct, allowing you to stream all rows from the table.
- Updatable
Entity - Trait for types that can be updated in the database. An “Updatable” struct is generated for each entity, containing the primary key(s) and updatable fields.
Derive Macros§
- Entity
- Generate the entity