diesel-crud

Crates.iodiesel-crud
lib.rsdiesel-crud
version0.2.0
sourcesrc
created_at2020-02-20 20:39:04.902539
updated_at2020-02-26 17:16:46.506209
descriptionPerscriptive Diesel CRUD and connection pool management
homepage
repositoryhttps://github.com/vadixidav/diesel-crud
max_upload_size
id210990
size10,009
Geordon Worley (vadixidav)

documentation

https://docs.rs/diesel-crud/

README

diesel-crud

Crates.io MIT/Apache docs.rs LoC

Perscriptive API that makes it trivial implement simple CRUD operations with Diesel using Rust traits and auto-manages the connection pool

This crate is in the early stages and will be modified as more functionality is required from the ground-up.

Example

The following could be your crate for specifying your API at the type level. You then just need REST endpoints that take JSON that serializes into these types that then updates the database appropriately.

#[macro_use]
extern crate diesel;

pub mod schema;

use diesel::{Insertable, Queryable};
use diesel_crud::{Create, Load};
use schema::*;
use serde::{Deserialize, Serialize};

type Conn = diesel::pg::PgConnection;

#[derive(Debug, Clone, Serialize, Deserialize, Insertable)]
#[table_name = "users"]
pub struct CreateUser {
    pub username: String,
}

impl Create for CreateUser {
    type Table = users::table;

    fn table() -> Self::Table {
        users::table
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Queryable)]
pub struct User {
    pub id: i32,
    pub username: String,
}

struct GetUsers;

impl Load<Conn> for GetUsers {
    type Item = User;
    type Query = users::table;

    fn query(self) -> Self::Query {
        users::table
    }
}
Commit count: 13

cargo fmt