5个版本
0.2.0 | 2020年2月26日 |
---|---|
0.1.3 | 2020年2月26日 |
0.1.2 | 2020年2月20日 |
0.1.1 | 2020年2月20日 |
0.1.0 | 2020年2月20日 |
#1148 in HTTP服务器
9KB
148 行
diesel-crud
使用Rust特性和自动管理连接池的简单CRUD操作的规范API
该包处于早期阶段,并将根据所需的功能进行修改。
示例
以下可以成为您的包,用于在类型级别指定API。然后您只需要REST端点,这些端点接收JSON,并将其序列化到这些类型中,然后相应地更新数据库。
#[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
}
}
依赖项
~4–9.5MB
~90K SLoC