Generate db entities and create state struct
This commit is contained in:
parent
8e4adedf98
commit
aecaf0cca3
9 changed files with 1608 additions and 15 deletions
1525
Cargo.lock
generated
1525
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,3 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
## Database
|
||||
sea-orm = { version = "^0.11", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] }
|
||||
|
||||
## NATS Wire Protocol
|
||||
async-nats = "0.29.0"
|
32
slop-common/src/db/entities/key_pair.rs
Normal file
32
slop-common/src/db/entities/key_pair.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "key_pair")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false, column_type = "Text")]
|
||||
pub user: String,
|
||||
pub public: String,
|
||||
pub private: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::User",
|
||||
to = "super::user::Column::Id",
|
||||
on_update = "NoAction",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
User,
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
6
slop-common/src/db/entities/mod.rs
Normal file
6
slop-common/src/db/entities/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod key_pair;
|
||||
pub mod user;
|
4
slop-common/src/db/entities/prelude.rs
Normal file
4
slop-common/src/db/entities/prelude.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
pub use super::key_pair::Entity as KeyPair;
|
||||
pub use super::user::Entity as User;
|
41
slop-common/src/db/entities/user.rs
Normal file
41
slop-common/src/db/entities/user.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "user")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false, column_type = "Text")]
|
||||
pub id: String,
|
||||
pub activated: bool,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub username: String,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub email: String,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub password_hash: String,
|
||||
#[sea_orm(column_type = "Text", nullable)]
|
||||
pub mfa_key: Option<String>,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub display_name: String,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub summary: String,
|
||||
pub created: DateTime,
|
||||
pub manually_approves_followers: bool,
|
||||
pub discoverable: bool,
|
||||
pub always_mark_as_nsfw: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::key_pair::Entity")]
|
||||
KeyPair,
|
||||
}
|
||||
|
||||
impl Related<super::key_pair::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::KeyPair.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
1
slop-common/src/db/mod.rs
Normal file
1
slop-common/src/db/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod entities;
|
|
@ -1,3 +1,6 @@
|
|||
pub struct SlopState {
|
||||
pub mod db;
|
||||
|
||||
}
|
||||
pub struct SlopState {
|
||||
conn: sea_orm::DatabaseConnection,
|
||||
nats_client: async_nats::Client,
|
||||
}
|
||||
|
|
|
@ -6,3 +6,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
## Database
|
||||
sea-orm = { version = "^0.11", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] }
|
Loading…
Add table
Reference in a new issue