| Crates.io | ergol |
| lib.rs | ergol |
| version | 0.1.9 |
| created_at | 2020-11-23 10:55:47.559605+00 |
| updated_at | 2025-03-12 09:42:20.741063+00 |
| description | an async ORM for Rust |
| homepage | https://ergol-rs.github.io |
| repository | https://github.com/polymny/ergol/tree/dev/ergol |
| max_upload_size | |
| id | 315336 |
| size | 93,376 |
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.