stage 1 of switching from raw sqlx to sea_orm
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-07-06 23:21:34 +02:00
parent 6ed7b16bf6
commit 26e39c7c06
53 changed files with 1201 additions and 710 deletions

2
neo-entity/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/target
/Cargo.lock

12
neo-entity/Cargo.toml Normal file
View File

@@ -0,0 +1,12 @@
[package]
name = "neo-entity"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
chrono = {version = "0.4", features = ["serde"] }
sea-orm = { version = "^0.8", features = ["macros", "with-chrono", "with-uuid", "with-json"], default-features = false }
serde = "1.0"
serde_json = "1.0"
uuid = { version = "*", features = ["v4", "serde"]}

39
neo-entity/src/devices.rs Normal file
View File

@@ -0,0 +1,39 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "devices")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uuid: Uuid,
pub user_uuid: Uuid,
pub device_id: String,
pub display_name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserUuid",
to = "super::users::Column::Uuid",
on_update = "NoAction",
on_delete = "NoAction"
)]
Users,
#[sea_orm(has_many = "super::sessions::Entity")]
Sessions,
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl Related<super::sessions::Entity> for Entity {
fn to() -> RelationDef {
Relation::Sessions.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

48
neo-entity/src/events.rs Normal file
View File

@@ -0,0 +1,48 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "events")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uuid: String,
pub room_uuid: String,
pub r#type: String,
pub state_key: Option<String>,
pub sender_uuid: String,
pub origin_server_ts: i32,
pub content: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::SenderUuid",
to = "super::users::Column::Uuid",
on_update = "NoAction",
on_delete = "NoAction"
)]
Users,
#[sea_orm(
belongs_to = "super::rooms::Entity",
from = "Column::RoomUuid",
to = "super::rooms::Column::Uuid",
on_update = "NoAction",
on_delete = "NoAction"
)]
Rooms,
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl Related<super::rooms::Entity> for Entity {
fn to() -> RelationDef {
Relation::Rooms.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

3
neo-entity/src/lib.rs Normal file
View File

@@ -0,0 +1,3 @@
pub mod users;
pub mod devices;
pub mod sessions;

23
neo-entity/src/rooms.rs Normal file
View File

@@ -0,0 +1,23 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "rooms")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uuid: String,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::events::Entity")]
Events,
}
impl Related<super::events::Entity> for Entity {
fn to() -> RelationDef {
Relation::Events.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,30 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "sessions")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uuid: Uuid,
pub device_uuid: Uuid,
pub key: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::devices::Entity",
from = "Column::DeviceUuid",
to = "super::devices::Column::Uuid",
on_update = "NoAction",
on_delete = "NoAction"
)]
Devices,
}
impl Related<super::devices::Entity> for Entity {
fn to() -> RelationDef {
Relation::Devices.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

25
neo-entity/src/users.rs Normal file
View File

@@ -0,0 +1,25 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uuid: Uuid,
pub user_id: String,
pub display_name: String,
pub password_hash: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::devices::Entity")]
Devices
}
impl Related<super::devices::Entity> for Entity {
fn to() -> RelationDef {
Relation::Devices.def()
}
}
impl ActiveModelBehavior for ActiveModel {}