sprattus-derive

Crates.iosprattus-derive
lib.rssprattus-derive
version0.0.1
sourcesrc
created_at2019-10-18 15:21:27.918367
updated_at2019-10-18 15:21:27.918367
descriptionThe derive macros for a async orm for Postgres
homepage
repositoryhttps://github.com/dutchmartin/sprattus
max_upload_size
id173703
size18,987
Martijn Groeneveldt (dutchmartin)

documentation

README

sprattus, the async Rust ORM for Postgres

The Future .awaits

sprattus is a crate that let's you easily do async CRUD operations on your Postgres database with Rust structs.

Getting started

Add sprattus to your cargo.toml:

sprattus = "0.0.1"

Create a table in Postgres:

CREATE TABLE fruits(
   id SERIAL PRIMARY KEY,
   name VARCHAR NOT NULL
);

Create a struct corresponding to the created table:

struct Fruit {
    id: i32,
    name: String
}

And finally add the sprattus macro's and annotations:

use sprattus::*;

#[derive(ToSql, FromSql, Debug)]
#[sql(table = "fruits")]
struct Fruit {
    #[sql(primary_key)]
    id: i32,
    name: String
}

And now you're ready to use the client in combination with you freshly created struct!

use tokio::prelude::*;
use sprattus::*;

#[derive(ToSql, FromSql)]
#[sql(table = "fruits")]
struct Fruit {
    #[sql(primary_key)]
    id: i32,
    name: String
}

#[tokio::main]
async fn main() -> Result<(), Error>{
    let conn = PGConnection::new("postgresql://localhost/dellstore2?user=tg").await.unwrap();
    let fruit = Fruit{
        id: 0,
        name: String::from("apple")
    };
    let created_fruit = conn.create(fruit).await?;
    dbg!(created_fruit);
    Ok(())
}

Please check out the docs for further reference.

Commit count: 115

cargo fmt