Crates.io | adom |
lib.rs | adom |
version | 0.0.6 |
source | src |
created_at | 2021-04-09 18:43:18.915182 |
updated_at | 2022-07-29 13:34:44.657015 |
description | async-postgres macros for object mapping |
homepage | |
repository | https://github.com/lex148/adom |
max_upload_size | |
id | 381418 |
size | 28,076 |
This crate is a set of macros used to generate simple CRUD functions for your Serde structs
Adom is not intended to be a full on ORM like diesel. Its for the people that want to use the postgres driver directly. But want to eliminate some of the boiler plate code on their simple table objects.
A simple example of using adom in a project can be found here
Add an attribute to the top of your struct to connect it to the DB table
#[AdomTable = "orders"]
pub struct Order{
id: i32,
customer: String,
total: f64,
}
Congratulations nothing happened, but you can now use Adom
To use Adom add derive statements to add useful functions to your struct
#[derive(Deserialize, AdomSelect, AdomUpdate, AdomCreate, AdomDelete)]
#[AdomTable = "orders"]
pub struct Order{
id: i32,
customer: String,
total: f64,
}
Each derive adds functions related to the DB action. Add only what you want or need
AdomSelect
AdomCreate
AdomUpdate
AdomDelete
There are a couple of helper attributes that modify the behavior of Adom
AdomColumn - used to if the struct field name doesn't match the DB columns name
#[derive(Deserialize, AdomSelect, AdomUpdate, AdomCreate, AdomDelete)]
#[AdomTable = "orders"]
pub struct Order{
id: i32,
#[AdomColumn = "customer_name"]
customer: String,
total: f64,
}
AdomIgnore - ignore a field on your struct
#[derive(Deserialize, AdomSelect, AdomUpdate, AdomCreate, AdomDelete)]
#[AdomTable = "orders"]
pub struct Order{
id: i32,
customer: String,
total: f64,
#[AdomIgnore]
random_extra_field_that_has_nothing_to_do_with_db: Vec<u8>,
}
AdomAuditable - auto fill and update the traditional DB auditing fields
#[derive(Deserialize, AdomSelect, AdomUpdate, AdomCreate, AdomDelete)]
#[AdomTable = "orders"]
#[AdomAuditable]
pub struct Order{
id: i32,
customer: String,
total: f64,
updated_at: SystemTime,
created_at: SystemTime,
updated_by: String,
created_by: String,
}