Giter Site home page Giter Site logo

welds's Introduction

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

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.

welds's People

Contributors

lex148 avatar cajun avatar sunnyregion avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.