Generate db entities and create state struct

This commit is contained in:
Evie Viau-Chow-Stuart 2023-06-20 20:19:40 -04:00
parent 8e4adedf98
commit aecaf0cca3
Signed by: evie
GPG key ID: 928652CDFCEC8099
9 changed files with 1608 additions and 15 deletions

1525
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -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"

View 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 {}

View 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;

View 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;

View 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 {}

View file

@ -0,0 +1 @@
pub mod entities;

View file

@ -1,3 +1,6 @@
pub struct SlopState {
pub mod db;
pub struct SlopState {
conn: sea_orm::DatabaseConnection,
nats_client: async_nats::Client,
}

View file

@ -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"] }