ssql

Crates.iossql
lib.rsssql
version0.2.0
sourcesrc
created_at2023-08-21 01:50:02.106566
updated_at2024-05-13 06:18:02.717128
descriptionAsync ms sql server basic orm
homepage
repositoryhttps://github.com/Geo-W/ssql
max_upload_size
id949643
size90,216
(Geo-W)

documentation

README

An easy-to use basic mssql server ORM based on tiberius.

This crate is still under construction, apis may subject to change.
For full documentation pls visit doc.rs.

Quick Glance:

When defining structs, make sure keep the field sequence consistent with the sequence in database as bulk insert(insert_many) depends on it.

use ssql::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(ORM, Debug, Default, Serialize, Deserialize)]
#[ssql(table = Person, schema = SCHEMA1)] // other schema
struct Person {
    #[ssql(primary_key)]
    id: i32,
    email: Option<String>, // wrap nullable column in option
}

#[derive(ORM, Debug, Default, Serialize, Deserialize)]
#[ssql(table = Posts)] // default schema
struct Posts {
    id: i32,
    post: String,
    #[ssql(foreign_key = "SCHEMA1.Person.id")] // if it belongs to default schema, just write TABLE.COLUMN
    person_id: i32,
}

async fn _get<'a>(client: &'a mut tiberius::Client<Compat<TcpStream>>) -> SsqlResult<()> { 
    let mut query = Person::query();

    // return Vec<Person>
    let vec1 = query.all(client).await?;

    // return Vec<Value>
    let js = query.json(client).await?;

    // return Polars DataFrame
    let df = query.df(client).await?;

    // return Vec<(Person, Posts)>
    let query = query.left_join::<Posts>();
    let vec2 = query.all(client).await?;

    Ok(())
}

TODO:

  • handle multiple relationships
  • build filter pattern
  • support raw sql string query
  • handle non-manual input key like auto-generated id
  • handle GROUP BY aggregation
  • support filter with decorated col like WHERE YEAR(datetime_col) = ?
Commit count: 101

cargo fmt