25 releases

0.4.5 Oct 26, 2024
0.4.1 Sep 6, 2024
0.3.7 Jul 19, 2024
0.3.1 Mar 11, 2024
0.1.7 May 18, 2023

#80 in Database interfaces

Download history 274/week @ 2024-07-15 64/week @ 2024-07-22 253/week @ 2024-07-29 11/week @ 2024-08-05 166/week @ 2024-08-12 40/week @ 2024-08-19 48/week @ 2024-08-26 120/week @ 2024-09-02 114/week @ 2024-09-09 114/week @ 2024-09-16 110/week @ 2024-09-23 282/week @ 2024-09-30 495/week @ 2024-10-07 132/week @ 2024-10-14 298/week @ 2024-10-21 183/week @ 2024-10-28

1,114 downloads per month
Used in welds-cli

BSD-3-Clause

350KB
9K SLoC

An async ORM written in rust using sqlx and/or Tiberius.

Welds

Welds is an async ORM written in rust using sqlx and/or Tiberius.

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.
  • Low level connection always available when you need to drop down to raw SQL.

Under the hood welds uses:

  • sqlx for Postgres, MySql, and Sqlite.
  • Tiberius for MSSQL

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

Example Setup

#[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>,
}

Example Usage

Basic Select

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

Basic Filter Across tables

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

Create And Update

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

Other Examples

For more good examples check out the examples repo.

Dependencies

~0.4–20MB
~247K SLoC