Crate ergol

source ·
Expand description

CI Docs Book

This crate provides the #[ergol] macro. It allows to persist the data in a database. For example, you just have to write

use ergol::prelude::*;

pub struct User {
    #[id] pub id: i32,
    #[unique] pub username: String,
    pub password: String,
    pub age: Option<i32>,

and the #[ergol] macro will generate most of the code you will need. You’ll then be able to run code like the following:

// Drop the user table if it exists

// Create the user table

// Create a user and save it into the database
let mut user: User = User::create("thomas", "pa$$w0rd", Some(28)).save(&client).await?;

// Change some of its fields
*user.age.as_mut().unwrap() += 1;

// Update the user in the database;

// Fetch a user by its username thanks to the unique attribute
let user: Option<User> = User::get_by_username("thomas", &client).await?;

// Select all users
let users: Vec<User> = User::select().execute(&client).await?;

See the book for more information.



  • This module contains the types for postgres.
  • The prelude contains the macros and usefull traits.
  • This crate contains all the necessary queries.
  • This module contains the struct that we use to represent the relationships between linked tables.


  • The type that wraps the connection to the database.


  • Any type that should be transformed into a table should implement this trait.


  • Connects to the specified database.

Attribute Macros

Derive Macros

  • Any enum that has no field on any variant can derive PgEnum in order to be usable in a #[ergol] struct.