Crates.io | welds-macros |
lib.rs | welds-macros |
version | 0.4.8 |
source | src |
created_at | 2023-04-13 00:59:22.986535 |
updated_at | 2024-11-22 12:14:22.915609 |
description | Macros for the welds ORM |
homepage | |
repository | https://github.com/weldsorm/welds |
max_upload_size | |
id | 837754 |
size | 59,140 |
Under the hood welds uses:
Compatibility:
the 0.4.*
line of welds is compiled with sqlx 0.8
the 0.3.*
line of welds is compiled with sqlx 0.7
#[derive(Debug, WeldsModel)]
#[welds(schema= "inventory", table = "products")]
#[welds(BelongsTo(seller, super::people::People, "seller_id"))]
pub struct Product {
#[welds(rename = "product_id")]
#[welds(primary_key)]
pub id: i32,
pub name: String,
pub seller_id: Option<i32>,
pub description: Option<String>,
pub price: Option<f32>,
}
let url = "postgres://postgres:password@localhost:5432";
let client = welds::connections::postgres::connect(url).await.unwrap();
let products = Product::where_col(|p| p.price.equal(3.50)).run(&client).await?;
let client = welds::connections::mssql::connect(url).await.unwrap();
let sellers = Product::where_col(|product| product.price.equal(3.50))
.map_query(|product| product.seller )
.where_col(|seller| seller.name.ilike("%Nessie%") )
.run(&client).await?;
let client = welds::connections::sqlite::connect(url).await.unwrap();
let mut cookies = Product::new();
cookies.name = "cookies".to_owned();
// Creates the product cookie
cookies.save.await(&client)?;
cookies.description = "Yum".to_owned();
// Updates the Cookies
cookies.save.await(&client)?;
For more good examples check out the examples repo.