#[derive(Debug, sqlx::FromRow, WeldsModel)]
#[welds(db(Postgres))]
//#[welds(db(Postgres, Mssql, Mysql, Sqlite))]
#[welds(schema= "inventory", table = "products")]
#[welds(BelongsTo(seller, super::people::People, "seller_id"))]
pub struct Product {
#[sqlx(rename = "product_id")]
#[welds(primary_key)]
pub id: i32,
pub name: String,
pub seller_id: Option,
pub description: Option,
pub price: Option,
}
let url = "postgres://postgres:password@localhost:5432";
let pool = welds::connection::connect_postgres(url).await.unwrap();
let products = Product::where_col(|p| p.price.equal(3.50)).run(&pool).await?;
let conn = welds::connection::connect_mssql(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(&conn).await?;
let conn = welds::connection::connect_sqlite(url).await.unwrap();
let mut cookies = Product::new();
cookies.name = "cookies".to_owned();
// Creates the product cookie
cookies.save.await(&conn)?;
cookies.description = "Yum".to_owned();
// Updates the Cookies
cookies.save.await(&conn)?;
tables:
- schema: public
name: orders
manual_update: false
model: null
type: table
columns:
- db_name: id
db_type: int8
model_name: id
is_null: false
primary_key: true
writeable: true
- ...
页面更新:2024-02-17
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号