Files
helios-server-rs/src/model/db_model.rs
2024-08-12 22:40:43 +08:00

165 lines
3.9 KiB
Rust

use crate::model::schema;
use diesel::prelude::*;
use chrono::{DateTime, Utc};
#[derive(Queryable, Selectable, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = schema::categories)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Category {
id: i64,
uid: i64,
name: String,
level: i32,
parent_category_id: i64,
book_id: i64,
is_delete: bool,
create_at: chrono::NaiveDateTime,
update_at: chrono::NaiveDateTime,
}
#[derive(serde::Deserialize, Insertable)]
#[diesel(table_name = schema::categories)]
pub struct CategoryForm {
pub uid: i64,
pub name: String,
pub book_id: i64,
pub level: i32,
pub parent_category_id: i64,
}
#[derive(Queryable, Selectable, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = schema::tags)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Tag {
id: i64,
uid: i64,
book_id: i64,
name: String,
level: i32,
parent_tag_id: i64,
is_delete: bool,
create_at: chrono::NaiveDateTime,
update_at: chrono::NaiveDateTime,
}
#[derive(serde::Deserialize, Insertable)]
#[diesel(table_name = schema::tags)]
pub struct TagForm {
pub uid: i64,
pub book_id: i64,
pub name: String,
pub level: i32,
pub parent_tag_id: i64,
}
#[derive(Queryable, Selectable, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = schema::books)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Book {
id: i64,
uid: i64,
name: String,
is_delete: bool,
create_at: chrono::NaiveDateTime,
update_at: chrono::NaiveDateTime,
}
#[derive(serde::Deserialize, Insertable)]
#[diesel(table_name = schema::books)]
pub struct BookForm {
pub uid: i64,
pub name: String,
}
#[derive(Queryable, Selectable, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = schema::accounts)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Account {
id: i64,
uid: i64,
name: String,
account_type: i64,
is_delete: bool,
create_at: chrono::NaiveDateTime,
update_at: chrono::NaiveDateTime,
}
#[derive(serde::Deserialize, Insertable)]
#[diesel(table_name = schema::accounts)]
pub struct AccountForm {
pub uid: i64,
pub name: String,
pub account_type: i64,
}
#[derive(Queryable, Selectable, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = schema::transactions)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Transaction {
pub id: i64,
uid: i64,
pub book_id: i64,
pub description: String,
pub category_id: i64,
pub time: chrono::DateTime<Utc>,
is_delete: bool,
create_at: chrono::NaiveDateTime,
update_at: chrono::NaiveDateTime,
}
#[derive(serde::Deserialize, Insertable)]
#[diesel(table_name = schema::transactions)]
pub struct TransactionForm {
pub id: Option<i64>,
pub uid: i64,
pub book_id: i64,
pub description: String,
pub category_id: i64,
pub time: chrono::DateTime<Utc>,
}
#[derive(Queryable, Selectable, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = schema::amounts)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Amount {
pub id: i64,
uid: i64,
account_id: i64,
transaction_id: i64,
value: i64,
expo: i64,
currency: String,
is_delete: bool,
create_at: chrono::NaiveDateTime,
update_at: chrono::NaiveDateTime,
}
#[derive(serde::Deserialize, Insertable)]
#[diesel(table_name = schema::amounts)]
pub struct AmountForm {
pub uid: i64,
pub transaction_id: i64,
pub account_id: i64,
pub value: i64,
pub expo: i64,
pub currency: String,
}
#[derive(Queryable, Selectable, serde::Serialize)]
#[diesel(table_name = schema::users)]
pub struct User {
pub id: i64,
pub username: String,
pub password: String,
pub mail: String,
pub is_delete: bool,
}
#[derive(Insertable)]
#[diesel(table_name = schema::users)]
pub struct UserForm {
pub username: String,
pub password: String,
pub mail: String,
}