summaryrefslogtreecommitdiffstats
path: root/src/model.rs
blob: 1d399dafa2212879ba966a6a586823dc42926d2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use actix::{Actor, SyncContext};
use chrono::NaiveDateTime;
use diesel::mysql::MysqlConnection;
use r2d2::Pool;
use r2d2_diesel::ConnectionManager;

use crate::schema::{passwords, transactions, users};

pub struct DbExecutor(pub Pool<ConnectionManager<MysqlConnection>>);

impl Actor for DbExecutor {
    type Context = SyncContext<Self>;
}

#[derive(Debug, Clone, Insertable)]
#[table_name = "transactions"]
pub struct NewTransaction<'a> {
    pub sender: u64,
    pub receiver: u64,
    pub amount: u64,
    pub sender_balance: u64,
    pub receiver_balance: u64,
    pub purpose: &'a str,
}

#[derive(Debug, Clone, Queryable)]
pub struct User {
    pub id: u64,
    pub power_level: i32,
    pub name: String,
    pub created: NaiveDateTime,
    pub balance: u64,
}

#[derive(Debug, Clone, Insertable)]
#[table_name = "users"]
pub struct NewUser {
    pub power_level: i32,
    pub name: String,
    pub balance: u64,
}

#[derive(Debug, Clone, Queryable)]
pub struct Password {
    pub id: u64,
    pub hash: String,
}

#[derive(Debug, Clone, Insertable)]
#[table_name = "passwords"]
pub struct NewPassword<'a> {
    pub id: u64,
    pub hash: &'a str,
}