Dev (#1)
* init * bot framework done * here and ready for orm * might use sea-orm * orm done * use teloxide * ready to go? * 需要完成命令部分 * 需要完成:list_handler() * 查询用户名应当以@开头 * use rustls to avoid segfault? * postgresql ready * inline query done * list_handler * flattern code * test needed * ready to build * some bugs * almost done * ready to take off Co-authored-by: senset <dummy@dummy.d>
This commit is contained in:
12
entity/Cargo.toml
Normal file
12
entity/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "models"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "models"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "^0.8.0"
|
4
entity/src/entities/mod.rs
Normal file
4
entity/src/entities/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod prelude;
|
||||
|
||||
pub mod record;
|
||||
pub mod user;
|
8
entity/src/entities/prelude.rs
Normal file
8
entity/src/entities/prelude.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
pub use super::record::{
|
||||
ActiveModel as RecordActiveModel, Column as RecordColumn, Entity as Record,
|
||||
Model as RecordModel, PrimaryKey as RecordPrimaryKey, Relation as RecordRelation,
|
||||
};
|
||||
pub use super::user::{
|
||||
ActiveModel as UserActiveModel, Column as UserColumn, Entity as User, Model as UserModel,
|
||||
PrimaryKey as UserPrimaryKey, Relation as UserRelation,
|
||||
};
|
35
entity/src/entities/record.rs
Normal file
35
entity/src/entities/record.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "records")]
|
||||
pub struct Model {
|
||||
/// internal ID
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
|
||||
/// relation user id
|
||||
#[sea_orm(indexed)]
|
||||
pub user_id: i64,
|
||||
|
||||
/// records
|
||||
#[sea_orm(indexed, column_type = "Text", unique)]
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::user::Column::Id"
|
||||
)]
|
||||
User,
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
35
entity/src/entities/user.rs
Normal file
35
entity/src/entities/user.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
/// internal ID
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
|
||||
/// Telegram user ID
|
||||
#[sea_orm(unique)]
|
||||
pub tg_uid: i64,
|
||||
|
||||
/// Telegram user name
|
||||
#[sea_orm(nullable)]
|
||||
pub username: Option<String>,
|
||||
|
||||
/// use notify
|
||||
#[sea_orm(default_value = true)]
|
||||
pub notify: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::record::Entity")]
|
||||
Record,
|
||||
}
|
||||
|
||||
impl Related<super::record::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Record.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
2
entity/src/lib.rs
Normal file
2
entity/src/lib.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod entities;
|
||||
pub use entities::*;
|
Reference in New Issue
Block a user