Expand description
Derive macro for sqlx to implement Create, Read, Update, and Delete (CRUD) methods.
Use
adding the following to your project’s Cargo.toml:
[dependencies]
co-orm = { virsion = "0.1", features = ["mysql"] }
sqlx = { version = "0.6", features = ["mysql"] }Examples
use co_orm::{Crud, FromRow};
#[derive(Debug, Crud, FromRow)]
#[orm_rename = "users"]
pub struct User {
#[orm_pk]
pub id: u64,
#[orm_by]
#[orm_update]
#[orm_rename = "name"]
pub name: Option<String>,
#[orm_ignore]
pub add: String,
}
// use crud
let u = User::get(&pool, 1).await.unwrap();
println!("get {:?}", u);
let u = User::get_by(&pool, "id=1").await.unwrap();
println!("get_by {:?}", u);