11 releases

new 0.2.1 Sep 17, 2023
0.2.0 Sep 9, 2023
0.1.9 Sep 9, 2023
0.1.8 Aug 1, 2023
0.1.4 Apr 25, 2023

#7 in #database-interfaces

Download history 36/week @ 2023-05-30 41/week @ 2023-06-06 48/week @ 2023-06-13 40/week @ 2023-06-20 17/week @ 2023-06-27 39/week @ 2023-07-04 34/week @ 2023-07-11 33/week @ 2023-07-18 40/week @ 2023-07-25 88/week @ 2023-08-01 59/week @ 2023-08-08 25/week @ 2023-08-15 25/week @ 2023-08-22 45/week @ 2023-08-29 128/week @ 2023-09-05 135/week @ 2023-09-12

335 downloads per month
Used in 2 crates (via welds)

BSD-3-Clause

43KB
1K SLoC

An async ORM written in rust using the sqlx framework.

Welds

Welds is an async ORM written in rust using the sqlx framework.

Features

  • Async for all.
  • Support for multiple SQL databases (Mssql, MySql, Postgres, Sqlite)
  • Written for ease of development. Features aren't hidden behind traits. Code should be simple to write, and simple to read.
  • sqlx always available when you need to drop down to something lower level

Example Setup

#[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<i32>,
    pub description: Option<String>,
    pub price: Option<f32>,
}

Example Usage

Basic Select

  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?;

Basic Filter Across tables

  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?;

Create And Update

  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)?; 

Other Examples

For more good examples check out the examples repo.

Dependencies

~8–23MB
~390K SLoC