Skip to content

Antony1060/gas-orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

197 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gas-orm

A very simple Postgres ORM in Rust, made as a University project. Not production ready.

Basic usage for now

#[gas::model(table_name = "persons")]
#[derive(Debug, Clone)]
pub struct Person {
    #[primary_key]
    #[serial]
    pub id: i64,
    pub first_name: String,
    pub last_name: String,
    #[unique]
    pub email: String,
    pub phone_number: Option<String>,
    #[column(name = "bank_balance")]
    pub bank_account_balance: Decimal,
}

#[tokio::main]
async fn main() -> GasResult<()> {
    let conn =
        PgConnection::new_connection_pool("postgres://user:password@localhost/db")
            .await?;

    person::Model::create_table(&conn, true).await?;

    let persons = person::Model::query()
        .filter(|| {
            (person::bank_account_balance.gte(6000) & person::phone_number.is_not_null())
                | (person::id.gte(18) & person::phone_number.is_null())
        })
        .find_all(&conn)
        .await?;

    dbg!(&persons);

    Ok(())
}

Additionally add this in your build.rs to make compilations more correct sometimes

fn main() {
    println!("cargo:rerun-if-changed=migrations/");
}

About

Postgres ORM written in Rust focusing on DX and compile time safety.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages