Crates.io | diesel-crud |
lib.rs | diesel-crud |
version | 0.2.0 |
source | src |
created_at | 2020-02-20 20:39:04.902539 |
updated_at | 2020-02-26 17:16:46.506209 |
description | Perscriptive Diesel CRUD and connection pool management |
homepage | |
repository | https://github.com/vadixidav/diesel-crud |
max_upload_size | |
id | 210990 |
size | 10,009 |
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.
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
}
}