Kould kould commited on
Commit
c6d0d85
·
1 Parent(s): 6ad8d57

feat: impl dao (#1)

Browse files

Co-authored-by: kould <2435992353@qq.com>

Cargo.toml CHANGED
@@ -9,6 +9,11 @@ edition = "2021"
9
  actix-web = "4.3.1"
10
  actix-rt = "2.8.0"
11
  postgres = "0.19.7"
 
 
12
 
13
  [[bin]]
14
- name = "doc_gpt"
 
 
 
 
9
  actix-web = "4.3.1"
10
  actix-rt = "2.8.0"
11
  postgres = "0.19.7"
12
+ sea-orm = {version = "0.12.9", features = ["sqlx-postgres", "runtime-tokio-native-tls", "macros"]}
13
+ serde = { version = "1", features = ["derive"] }
14
 
15
  [[bin]]
16
+ name = "doc_gpt"
17
+
18
+ [workspace]
19
+ members = [".", "migration"]
migration/Cargo.toml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [package]
2
+ name = "migration"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ publish = false
6
+
7
+ [lib]
8
+ name = "migration"
9
+ path = "src/lib.rs"
10
+
11
+ [dependencies]
12
+ async-std = { version = "1", features = ["attributes", "tokio1"] }
13
+
14
+ [dependencies.sea-orm-migration]
15
+ version = "0.12.0"
16
+ features = [
17
+ "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
18
+ "sqlx-postgres", # `DATABASE_DRIVER` feature
19
+ ]
migration/README.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Running Migrator CLI
2
+
3
+ - Generate a new migration file
4
+ ```sh
5
+ cargo run -- generate MIGRATION_NAME
6
+ ```
7
+ - Apply all pending migrations
8
+ ```sh
9
+ cargo run
10
+ ```
11
+ ```sh
12
+ cargo run -- up
13
+ ```
14
+ - Apply first 10 pending migrations
15
+ ```sh
16
+ cargo run -- up -n 10
17
+ ```
18
+ - Rollback last applied migrations
19
+ ```sh
20
+ cargo run -- down
21
+ ```
22
+ - Rollback last 10 applied migrations
23
+ ```sh
24
+ cargo run -- down -n 10
25
+ ```
26
+ - Drop all tables from the database, then reapply all migrations
27
+ ```sh
28
+ cargo run -- fresh
29
+ ```
30
+ - Rollback all applied migrations, then reapply all migrations
31
+ ```sh
32
+ cargo run -- refresh
33
+ ```
34
+ - Rollback all applied migrations
35
+ ```sh
36
+ cargo run -- reset
37
+ ```
38
+ - Check the status of all migrations
39
+ ```sh
40
+ cargo run -- status
41
+ ```
migration/src/lib.rs ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pub use sea_orm_migration::prelude::*;
2
+
3
+ mod m20220101_000001_create_table;
4
+
5
+ pub struct Migrator;
6
+
7
+ #[async_trait::async_trait]
8
+ impl MigratorTrait for Migrator {
9
+ fn migrations() -> Vec<Box<dyn MigrationTrait>> {
10
+ vec![Box::new(m20220101_000001_create_table::Migration)]
11
+ }
12
+ }
migration/src/m20220101_000001_create_table.rs ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm_migration::prelude::*;
2
+
3
+ #[derive(DeriveMigrationName)]
4
+ pub struct Migration;
5
+
6
+ #[async_trait::async_trait]
7
+ impl MigrationTrait for Migration {
8
+ async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9
+ manager
10
+ .create_table(
11
+ Table::create()
12
+ .table(UserInfo::Table)
13
+ .if_not_exists()
14
+ .col(
15
+ ColumnDef::new(UserInfo::Uid)
16
+ .big_integer()
17
+ .not_null()
18
+ .auto_increment()
19
+ .primary_key(),
20
+ )
21
+ .col(ColumnDef::new(UserInfo::Email).string().not_null())
22
+ .col(ColumnDef::new(UserInfo::Nickname).string().not_null())
23
+ .col(ColumnDef::new(UserInfo::AvatarUrl).string())
24
+ .col(ColumnDef::new(UserInfo::ColorSchema).string().default("dark"))
25
+ .col(ColumnDef::new(UserInfo::ListStyle).string().default("list"))
26
+ .col(ColumnDef::new(UserInfo::Language).string().default("chinese"))
27
+ .col(ColumnDef::new(UserInfo::CreatedAt).date().not_null())
28
+ .col(ColumnDef::new(UserInfo::UpdatedAt).date().not_null())
29
+ .col(ColumnDef::new(UserInfo::IsDeleted).boolean().default(false))
30
+ .to_owned(),
31
+ )
32
+ .await?;
33
+
34
+ manager
35
+ .create_table(
36
+ Table::create()
37
+ .table(TagInfo::Table)
38
+ .if_not_exists()
39
+ .col(
40
+ ColumnDef::new(TagInfo::Uid)
41
+ .big_integer()
42
+ .not_null()
43
+ .auto_increment()
44
+ .primary_key(),
45
+ )
46
+ .col(ColumnDef::new(TagInfo::TagName).string().not_null())
47
+ .col(ColumnDef::new(TagInfo::Regx).string())
48
+ .col(ColumnDef::new(TagInfo::Color).big_integer().default(1))
49
+ .col(ColumnDef::new(TagInfo::Icon).big_integer().default(1))
50
+ .col(ColumnDef::new(TagInfo::Dir).string())
51
+ .col(ColumnDef::new(TagInfo::CreatedAt).date().not_null())
52
+ .col(ColumnDef::new(TagInfo::UpdatedAt).date().not_null())
53
+ .col(ColumnDef::new(TagInfo::IsDeleted).boolean().default(false))
54
+ .to_owned(),
55
+ )
56
+ .await?;
57
+
58
+ manager
59
+ .create_table(
60
+ Table::create()
61
+ .table(Tag2Doc::Table)
62
+ .if_not_exists()
63
+ .col(ColumnDef::new(Tag2Doc::TagId).big_integer())
64
+ .col(ColumnDef::new(Tag2Doc::Did).big_integer().comment("doc id, did in docinfo"))
65
+ .index(Index::create().col(Tag2Doc::TagId))
66
+ .to_owned(),
67
+ )
68
+ .await?;
69
+
70
+ manager
71
+ .create_table(
72
+ Table::create()
73
+ .table(Kb2Doc::Table)
74
+ .if_not_exists()
75
+ .col(ColumnDef::new(Kb2Doc::KbId).big_integer())
76
+ .col(ColumnDef::new(Kb2Doc::Did).big_integer().comment("doc id, did in docinfo"))
77
+ .index(Index::create().col(Kb2Doc::KbId))
78
+ .to_owned(),
79
+ )
80
+ .await?;
81
+
82
+ manager
83
+ .create_table(
84
+ Table::create()
85
+ .table(Dialog2Kb::Table)
86
+ .if_not_exists()
87
+ .col(ColumnDef::new(Dialog2Kb::DialogId).big_integer())
88
+ .col(ColumnDef::new(Dialog2Kb::KbId).big_integer())
89
+ .index(Index::create().col(Dialog2Kb::DialogId))
90
+ .to_owned(),
91
+ )
92
+ .await?;
93
+
94
+ manager
95
+ .create_table(
96
+ Table::create()
97
+ .table(Doc2Doc::Table)
98
+ .if_not_exists()
99
+ .col(ColumnDef::new(Doc2Doc::ParentId).big_integer().comment("doc id, did in docinfo"))
100
+ .col(ColumnDef::new(Doc2Doc::Did).big_integer().comment("doc id, did in docinfo"))
101
+ .index(Index::create().col(Doc2Doc::ParentId))
102
+ .to_owned(),
103
+ )
104
+ .await?;
105
+
106
+ manager
107
+ .create_table(
108
+ Table::create()
109
+ .table(KbInfo::Table)
110
+ .if_not_exists()
111
+ .col(ColumnDef::new(KbInfo::KbId).big_integer().auto_increment().not_null())
112
+ .col(ColumnDef::new(KbInfo::Uid).big_integer().not_null())
113
+ .col(ColumnDef::new(KbInfo::KbName).string().not_null())
114
+ .col(ColumnDef::new(KbInfo::Icon).big_integer().default(1))
115
+ .col(ColumnDef::new(KbInfo::CreatedAt).date().not_null())
116
+ .col(ColumnDef::new(KbInfo::UpdatedAt).date().not_null())
117
+ .col(ColumnDef::new(KbInfo::IsDeleted).boolean().default(false))
118
+ .index(Index::create().col(KbInfo::KbId))
119
+ .index(Index::create().col(KbInfo::Uid))
120
+ .to_owned(),
121
+ )
122
+ .await?;
123
+
124
+ manager
125
+ .create_table(
126
+ Table::create()
127
+ .table(DocInfo::Table)
128
+ .if_not_exists()
129
+ .col(ColumnDef::new(DocInfo::Did).big_integer().auto_increment().not_null())
130
+ .col(ColumnDef::new(DocInfo::Uid).big_integer().not_null())
131
+ .col(ColumnDef::new(DocInfo::DocName).string().not_null())
132
+ .col(ColumnDef::new(DocInfo::Size).big_integer().not_null())
133
+ .col(ColumnDef::new(DocInfo::Type).string().not_null()).comment("doc|folder")
134
+ .col(ColumnDef::new(DocInfo::KbProgress).float().default(0))
135
+ .col(ColumnDef::new(DocInfo::CreatedAt).date().not_null())
136
+ .col(ColumnDef::new(DocInfo::UpdatedAt).date().not_null())
137
+ .col(ColumnDef::new(DocInfo::IsDeleted).boolean().default(false))
138
+ .index(Index::create().col(DocInfo::Did))
139
+ .index(Index::create().col(DocInfo::Uid))
140
+ .to_owned(),
141
+ )
142
+ .await?;
143
+
144
+ manager
145
+ .create_table(
146
+ Table::create()
147
+ .table(DialogInfo::Table)
148
+ .if_not_exists()
149
+ .col(ColumnDef::new(DialogInfo::DialogId).big_integer().auto_increment().not_null())
150
+ .col(ColumnDef::new(DialogInfo::Uid).big_integer().not_null())
151
+ .col(ColumnDef::new(DialogInfo::DialogName).string().not_null())
152
+ .col(ColumnDef::new(DialogInfo::History).string().comment("json"))
153
+ .col(ColumnDef::new(DialogInfo::CreatedAt).date().not_null())
154
+ .col(ColumnDef::new(DialogInfo::UpdatedAt).date().not_null())
155
+ .col(ColumnDef::new(DialogInfo::IsDeleted).boolean().default(false))
156
+ .index(Index::create().col(DialogInfo::DialogId))
157
+ .index(Index::create().col(DialogInfo::Uid))
158
+ .to_owned(),
159
+ )
160
+ .await?;
161
+
162
+ Ok(())
163
+ }
164
+
165
+ async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
166
+ manager
167
+ .drop_table(Table::drop().table(UserInfo::Table).to_owned())
168
+ .await?;
169
+
170
+ manager
171
+ .drop_table(Table::drop().table(TagInfo::Table).to_owned())
172
+ .await?;
173
+
174
+ manager
175
+ .drop_table(Table::drop().table(Tag2Doc::Table).to_owned())
176
+ .await?;
177
+
178
+ manager
179
+ .drop_table(Table::drop().table(Kb2Doc::Table).to_owned())
180
+ .await?;
181
+
182
+ manager
183
+ .drop_table(Table::drop().table(Dialog2Kb::Table).to_owned())
184
+ .await?;
185
+
186
+ manager
187
+ .drop_table(Table::drop().table(Doc2Doc::Table).to_owned())
188
+ .await?;
189
+
190
+ manager
191
+ .drop_table(Table::drop().table(KbInfo::Table).to_owned())
192
+ .await?;
193
+
194
+ manager
195
+ .drop_table(Table::drop().table(DocInfo::Table).to_owned())
196
+ .await?;
197
+
198
+ manager
199
+ .drop_table(Table::drop().table(DialogInfo::Table).to_owned())
200
+ .await?;
201
+
202
+ Ok(())
203
+ }
204
+ }
205
+
206
+ #[derive(DeriveIden)]
207
+ enum UserInfo {
208
+ Table,
209
+ Uid,
210
+ Email,
211
+ Nickname,
212
+ AvatarUrl,
213
+ ColorSchema,
214
+ ListStyle,
215
+ Language,
216
+ CreatedAt,
217
+ UpdatedAt,
218
+ IsDeleted,
219
+ }
220
+
221
+ #[derive(DeriveIden)]
222
+ enum TagInfo {
223
+ Table,
224
+ Uid,
225
+ TagName,
226
+ Regx,
227
+ Color,
228
+ Icon,
229
+ Dir,
230
+ CreatedAt,
231
+ UpdatedAt,
232
+ IsDeleted,
233
+ }
234
+
235
+ #[derive(DeriveIden)]
236
+ enum Tag2Doc {
237
+ Table,
238
+ TagId,
239
+ Did,
240
+ }
241
+
242
+ #[derive(DeriveIden)]
243
+ enum Kb2Doc {
244
+ Table,
245
+ KbId,
246
+ Did,
247
+ }
248
+
249
+ #[derive(DeriveIden)]
250
+ enum Dialog2Kb {
251
+ Table,
252
+ DialogId,
253
+ KbId,
254
+ }
255
+
256
+ #[derive(DeriveIden)]
257
+ enum Doc2Doc {
258
+ Table,
259
+ ParentId,
260
+ Did,
261
+ }
262
+
263
+ #[derive(DeriveIden)]
264
+ enum KbInfo {
265
+ Table,
266
+ KbId,
267
+ Uid,
268
+ KbName,
269
+ Icon,
270
+ CreatedAt,
271
+ UpdatedAt,
272
+ IsDeleted,
273
+ }
274
+
275
+ #[derive(DeriveIden)]
276
+ enum DocInfo {
277
+ Table,
278
+ Did,
279
+ Uid,
280
+ DocName,
281
+ Size,
282
+ Type,
283
+ KbProgress,
284
+ CreatedAt,
285
+ UpdatedAt,
286
+ IsDeleted,
287
+ }
288
+
289
+ #[derive(DeriveIden)]
290
+ enum DialogInfo {
291
+ Table,
292
+ DialogId,
293
+ Uid,
294
+ DialogName,
295
+ History,
296
+ CreatedAt,
297
+ UpdatedAt,
298
+ IsDeleted,
299
+ }
migration/src/main.rs ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ use sea_orm_migration::prelude::*;
2
+
3
+ #[async_std::main]
4
+ async fn main() {
5
+ cli::run_cli(migration::Migrator).await;
6
+ }
src/api/mod.rs ADDED
File without changes
src/entity/dialog_2_kb.rs ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "dialog_2_kb")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub dialog_id: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub kb_id: i64,
11
+ }
12
+
13
+ #[derive(Debug, Clone, Copy, EnumIter)]
14
+ pub enum Relation {
15
+ DialogInfo,
16
+ KbInfo,
17
+ }
18
+
19
+ impl RelationTrait for Relation {
20
+ fn def(&self) -> RelationDef {
21
+ match self {
22
+ Self::DialogInfo => Entity::belongs_to(super::dialog_info::Entity)
23
+ .from(Column::DialogId)
24
+ .to(super::dialog_info::Column::DialogId)
25
+ .into(),
26
+ Self::KbInfo => Entity::belongs_to(super::kb_info::Entity)
27
+ .from(Column::KbId)
28
+ .to(super::kb_info::Column::KbId)
29
+ .into(),
30
+ }
31
+ }
32
+ }
33
+
34
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/dialog_info.rs ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "dialog_info")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub dialog_id: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub uid: i64,
11
+ pub dialog_name: String,
12
+ pub history: String,
13
+
14
+ pub created_at: DateTimeWithTimeZone,
15
+ pub updated_at: DateTimeWithTimeZone,
16
+ #[sea_orm(soft_delete_column)]
17
+ pub is_deleted: bool,
18
+ }
19
+
20
+ #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
21
+ pub enum Relation {}
22
+
23
+ impl Related<super::kb_info::Entity> for Entity {
24
+ fn to() -> RelationDef {
25
+ super::dialog_2_kb::Relation::KbInfo.def()
26
+ }
27
+
28
+ fn via() -> Option<RelationDef> {
29
+ Some(super::dialog_2_kb::Relation::DialogInfo.def().rev())
30
+ }
31
+ }
32
+
33
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/doc_2_doc.rs ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "doc_2_doc")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub parent_id: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub did: i64,
11
+ }
12
+
13
+ #[derive(Debug, Clone, Copy, EnumIter)]
14
+ pub enum Relation {
15
+ Parent,
16
+ Child
17
+ }
18
+
19
+ impl RelationTrait for Relation {
20
+ fn def(&self) -> RelationDef {
21
+ match self {
22
+ Self::Parent => Entity::belongs_to(super::doc_info::Entity)
23
+ .from(Column::ParentId)
24
+ .to(super::doc_info::Column::Did)
25
+ .into(),
26
+ Self::Child => Entity::belongs_to(super::doc_info::Entity)
27
+ .from(Column::Did)
28
+ .to(super::doc_info::Column::Did)
29
+ .into(),
30
+ }
31
+ }
32
+ }
33
+
34
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/doc_info.rs ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "doc_info")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub did: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub uid: i64,
11
+ pub doc_name: String,
12
+ pub size: i64,
13
+ #[sea_orm(column_name = "type")]
14
+ pub r#type: String,
15
+ pub kb_progress: f64,
16
+
17
+ pub created_at: DateTimeWithTimeZone,
18
+ pub updated_at: DateTimeWithTimeZone,
19
+ #[sea_orm(soft_delete_column)]
20
+ pub is_deleted: bool,
21
+ }
22
+
23
+ #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
24
+ pub enum Relation {}
25
+
26
+ impl Related<super::tag_info::Entity> for Entity {
27
+ fn to() -> RelationDef {
28
+ super::tag_2_doc::Relation::Tag.def()
29
+ }
30
+
31
+ fn via() -> Option<RelationDef> {
32
+ Some(super::tag_2_doc::Relation::DocInfo.def().rev())
33
+ }
34
+ }
35
+
36
+ impl Related<super::kb_info::Entity> for Entity {
37
+ fn to() -> RelationDef {
38
+ super::kb_2_doc::Relation::KbInfo.def()
39
+ }
40
+
41
+ fn via() -> Option<RelationDef> {
42
+ Some(super::kb_2_doc::Relation::DocInfo.def().rev())
43
+ }
44
+ }
45
+
46
+ impl Related<Entity> for Entity {
47
+ fn to() -> RelationDef {
48
+ super::doc_2_doc::Relation::Parent.def()
49
+ }
50
+
51
+ fn via() -> Option<RelationDef> {
52
+ Some(super::doc_2_doc::Relation::Child.def().rev())
53
+ }
54
+ }
55
+
56
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/kb_2_doc.rs ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "kb_2_doc")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub kb_id: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub uid: i64,
11
+ }
12
+
13
+ #[derive(Debug, Clone, Copy, EnumIter)]
14
+ pub enum Relation {
15
+ DocInfo,
16
+ KbInfo,
17
+ }
18
+
19
+ impl RelationTrait for Relation {
20
+ fn def(&self) -> RelationDef {
21
+ match self {
22
+ Self::DocInfo => Entity::belongs_to(super::doc_info::Entity)
23
+ .from(Column::Uid)
24
+ .to(super::doc_info::Column::Uid)
25
+ .into(),
26
+ Self::KbInfo => Entity::belongs_to(super::kb_info::Entity)
27
+ .from(Column::KbId)
28
+ .to(super::kb_info::Column::KbId)
29
+ .into(),
30
+ }
31
+ }
32
+ }
33
+
34
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/kb_info.rs ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "kb_info")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub kb_id: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub uid: i64,
11
+ pub kn_name: String,
12
+ pub icon: i64,
13
+
14
+ pub created_at: DateTimeWithTimeZone,
15
+ pub updated_at: DateTimeWithTimeZone,
16
+ #[sea_orm(soft_delete_column)]
17
+ pub is_deleted: bool,
18
+ }
19
+
20
+ #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
21
+ pub enum Relation {}
22
+
23
+ impl Related<super::doc_info::Entity> for Entity {
24
+ fn to() -> RelationDef {
25
+ super::kb_2_doc::Relation::DocInfo.def()
26
+ }
27
+
28
+ fn via() -> Option<RelationDef> {
29
+ Some(super::kb_2_doc::Relation::KbInfo.def().rev())
30
+ }
31
+ }
32
+
33
+ impl Related<super::dialog_info::Entity> for Entity {
34
+ fn to() -> RelationDef {
35
+ super::dialog_2_kb::Relation::DialogInfo.def()
36
+ }
37
+
38
+ fn via() -> Option<RelationDef> {
39
+ Some(super::dialog_2_kb::Relation::KbInfo.def().rev())
40
+ }
41
+ }
42
+
43
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/mod.rs ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ mod user_info;
2
+ mod tag_info;
3
+ mod tag_2_doc;
4
+ mod kb_2_doc;
5
+ mod dialog_2_kb;
6
+ mod doc_2_doc;
7
+ mod kb_info;
8
+ mod doc_info;
9
+ mod dialog_info;
src/entity/tag_2_doc.rs ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "tag_2_doc")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key, auto_increment = false)]
8
+ pub tag_id: i64,
9
+ #[sea_orm(primary_key, auto_increment = false)]
10
+ pub uid: i64,
11
+ }
12
+
13
+ #[derive(Debug, Clone, Copy, EnumIter)]
14
+ pub enum Relation {
15
+ DocInfo,
16
+ Tag,
17
+ }
18
+
19
+ impl RelationTrait for Relation {
20
+ fn def(&self) -> sea_orm::RelationDef {
21
+ match self {
22
+ Self::DocInfo => Entity::belongs_to(super::doc_info::Entity)
23
+ .from(Column::Uid)
24
+ .to(super::doc_info::Column::Uid)
25
+ .into(),
26
+ Self::Tag => Entity::belongs_to(super::tag_info::Entity)
27
+ .from(Column::TagId)
28
+ .to(super::tag_info::Column::Uid)
29
+ .into(),
30
+ }
31
+ }
32
+ }
33
+
34
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/tag_info.rs ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "tag_info")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key)]
8
+ #[serde(skip_deserializing)]
9
+ pub uid: i64,
10
+ pub tag_name: String,
11
+ pub regx: String,
12
+ pub color: i64,
13
+ pub icon: i64,
14
+ pub dir: String,
15
+
16
+ pub created_at: DateTimeWithTimeZone,
17
+ pub updated_at: DateTimeWithTimeZone,
18
+ #[sea_orm(soft_delete_column)]
19
+ pub is_deleted: bool,
20
+ }
21
+
22
+ #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
23
+ pub enum Relation {}
24
+
25
+ impl Related<super::doc_info::Entity> for Entity {
26
+ fn to() -> RelationDef {
27
+ super::tag_2_doc::Relation::DocInfo.def()
28
+ }
29
+
30
+ fn via() -> Option<RelationDef> {
31
+ Some(super::tag_2_doc::Relation::Tag.def().rev())
32
+ }
33
+ }
34
+
35
+ impl ActiveModelBehavior for ActiveModel {}
src/entity/user_info.rs ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use sea_orm::entity::prelude::*;
2
+ use serde::{Deserialize, Serialize};
3
+
4
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
5
+ #[sea_orm(table_name = "user_info")]
6
+ pub struct Model {
7
+ #[sea_orm(primary_key)]
8
+ #[serde(skip_deserializing)]
9
+ pub uid: i64,
10
+ pub email: String,
11
+ pub nickname: String,
12
+ pub avatar_url: String,
13
+ pub color_schema: String,
14
+ pub list_style: String,
15
+ pub language: String,
16
+
17
+ pub created_at: DateTimeWithTimeZone,
18
+ pub updated_at: DateTimeWithTimeZone,
19
+ #[sea_orm(soft_delete_column)]
20
+ pub is_deleted: bool,
21
+ }
22
+
23
+ #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
24
+ pub enum Relation {}
25
+
26
+ impl ActiveModelBehavior for ActiveModel {}
src/main.rs CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  use actix_web::{get, web, App, HttpServer, Responder};
2
 
3
  #[get("/")]
 
1
+ mod api;
2
+ mod entity;
3
+ mod service;
4
+
5
  use actix_web::{get, web, App, HttpServer, Responder};
6
 
7
  #[get("/")]
src/service/mod.rs ADDED
File without changes