mahjong_service/db_storage/
models.rs

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use super::schema::auth_info;
use super::schema::auth_info_anonymous;
use super::schema::auth_info_email;
use super::schema::auth_info_github;
use super::schema::game;
use super::schema::game_board;
use super::schema::game_draw_wall;
use super::schema::game_hand;
use super::schema::game_player;
use super::schema::game_score;
use super::schema::game_settings;
use super::schema::player;
use diesel::prelude::*;
use mahjong_core::game::GameVersion;
use mahjong_core::GameId;
use mahjong_core::PlayerId;

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = auth_info)]
pub struct DieselAuthInfo {
    pub provider: String,
    pub role: String,
    pub user_id: PlayerId,
}

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = auth_info_email)]
pub struct DieselAuthInfoEmail {
    pub hashed_pass: String,
    pub user_id: PlayerId,
    pub username: String,
}

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = auth_info_anonymous)]
pub struct DieselAuthInfoAnonymous {
    pub hashed_token: String,
    pub user_id: PlayerId,
}

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = auth_info_github)]
pub struct DieselAuthInfoGithub {
    pub token: Option<String>,
    pub user_id: PlayerId,
    pub username: String,
}

#[derive(Insertable, AsChangeset, Queryable, Selectable, Identifiable, PartialEq, Clone, Debug)]
#[diesel(treat_none_as_null = true)]
#[diesel(table_name = player)]
pub struct DieselPlayer {
    pub created_at: chrono::NaiveDateTime,
    pub id: PlayerId,
    pub is_ai: i32,
    pub name: String,
}

#[derive(Insertable, AsChangeset, Queryable, Selectable, Identifiable, PartialEq, Clone, Debug)]
#[diesel(treat_none_as_null = true)]
#[diesel(table_name = game)]
pub struct DieselGame {
    pub created_at: chrono::NaiveDateTime,
    pub id: GameId,
    pub name: String,
    pub phase: String,
    pub round_claimed_by: Option<PlayerId>,
    pub round_claimed_from: Option<PlayerId>,
    pub round_claimed_id: Option<i32>,
    pub round_consecutive_same_seats: i32,
    pub round_dealer_index: i32,
    pub round_east_player_index: i32,
    pub round_index: i32,
    pub round_initial_winds: Option<i32>,
    pub round_player_index: i32,
    pub round_wall_tile_drawn: Option<i32>,
    pub round_wind: String,
    pub style: String,
    pub updated_at: chrono::NaiveDateTime,
    pub version: GameVersion,
}

#[derive(Identifiable, Insertable, Selectable, Queryable, Associations, Debug)]
#[diesel(table_name = game_player)]
#[diesel(belongs_to(DieselGame, foreign_key = game_id))]
#[diesel(belongs_to(DieselPlayer, foreign_key = player_id))]
#[diesel(primary_key(game_id, player_id))]
pub struct DieselGamePlayer {
    pub game_id: GameId,
    pub player_id: PlayerId,
    pub player_index: i32,
}

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = game_score)]
pub struct DieselGameScore {
    pub game_id: GameId,
    pub player_id: PlayerId,
    pub score: i32,
}

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = game_board)]
pub struct DieselGameBoard {
    pub game_id: GameId,
    pub tile_id: i32,
    pub tile_index: i32,
}

#[derive(Insertable, Queryable, Clone, Debug)]
#[diesel(table_name = game_draw_wall)]
pub struct DieselGameDrawWall {
    pub game_id: GameId,
    pub tile_id: i32,
    pub tile_index: i32,
    pub place: String,
}

#[derive(Insertable, Queryable, Clone)]
#[diesel(table_name = game_hand)]
pub struct DieselGameHand {
    pub concealed: i32,
    pub game_id: GameId,
    pub player_id: String,
    pub set_id: Option<String>,
    pub tile_id: i32,
    pub tile_index: i32,
    pub is_kong: bool,
}

#[derive(Insertable, AsChangeset, Queryable, Clone)]
#[diesel(treat_none_as_null = true)]
#[diesel(table_name = game_settings)]
pub struct DieselGameSettings {
    pub ai_enabled: bool,
    pub auto_sort_players: String,
    pub auto_stop_claim_meld: String,
    pub discard_wait_ms: Option<i32>,
    pub fixed_settings: bool,
    pub game_id: GameId,
    pub last_discard_time: i64,
    pub dead_wall: bool,
}