7 releases

0.1.4 May 3, 2023
0.1.3 Mar 30, 2023
0.1.2 Sep 13, 2022
0.1.1 Sep 22, 2021
0.0.1 Nov 23, 2020

#905 in Database interfaces

Download history 12/week @ 2024-02-19 22/week @ 2024-02-26 16/week @ 2024-03-04 13/week @ 2024-03-11 22/week @ 2024-03-18 139/week @ 2024-04-01

175 downloads per month

MIT/Apache

36KB
734 lines

ergol

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::*;

#[ergol]
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
User::drop_table().execute(&client).await.ok();

// Create the user table
User::create_table().execute(&client).await?;

// 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
user.save(&client).await?;

// 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.

Dependencies

~9–46MB
~786K SLoC