Add SeaORM Entities

This commit is contained in:
fluo10 2025-04-27 19:22:46 +09:00
parent 0ed1fa97ee
commit 699a36d7ff
14 changed files with 2244 additions and 24 deletions

2056
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -3,10 +3,9 @@ members = ["dpts-*"]
[workspace.dependencies] [workspace.dependencies]
dpts-core = {path = "dpts-core"} dpts-core = {path = "dpts-core"}
anyhow = "1.0"
chrono = "0.4" chrono = "0.4"
thiserror = "2.0"
clap = "4.5" clap = "4.5"
dotenv = "0.15.0"
[workspace.package] [workspace.package]
version = "0.1.0" version = "0.1.0"

View file

@ -6,8 +6,6 @@ edition.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
dpts-core = { path = "../dpts-core" } dpts-core = {workspace = true}
anyhow = {workspace = true}
chrono = {workspace = true} chrono = {workspace = true}
clap = {version = "4.5.37", features=["derive"]} clap = {workspace = true, features = ["derive"]}
thiserror = {workspace = true}

View file

@ -1,11 +1,11 @@
pub mod error;
//mod label; //mod label;
mod record; mod record;
//use label::LabelArgs; //use label::LabelArgs;
use error::Error;
use record::{RecordArgs,RecordAddArgs}; use record::{RecordArgs,RecordAddArgs};
use dpts_core::error::Error;
use clap::{Args, CommandFactory, Parser, Subcommand}; use clap::{Args, CommandFactory, Parser, Subcommand};
use std::ffi::OsString; use std::ffi::OsString;

View file

@ -1,6 +1,6 @@
use chrono::prelude::*; use chrono::prelude::*;
use clap::{Args, Subcommand}; use clap::{Args, Subcommand};
use crate::Error; use dpts_core::error::Error;
use std::str::FromStr; use std::str::FromStr;
#[derive(Args, Clone, Debug)] #[derive(Args, Clone, Debug)]

View file

@ -6,7 +6,21 @@ edition.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
anyhow = {workspace = true} anyhow = "1.0"
async-graphql = "7.0"
axum = "0.8"
chrono = {workspace = true} chrono = {workspace = true}
clap = {workspace = true, features = ["derive"]} clap = {workspace = true}
thiserror = {workspace = true} dotenv = {workspace = true}
serde = { version = "1.0", features = ["derive"] }
thiserror = "2.0"
[dependencies.sea-orm]
version = "1.1"
features = [
"macros",
"debug-print",
"runtime-tokio-native-tls",
"sqlx-sqlite",
]
default-features = false

View file

@ -0,0 +1,4 @@
mod record_detail;
mod record_header;
mod record_tag;
mod user;

View file

@ -0,0 +1,46 @@
use async_graphql::*;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = "record_detail")]
#[graphql(concrete(name = "RecordDetail", params()))]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub record_header_id: i32,
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub record_tag_id: i32,
pub count: i32,
}
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::record_header::Entity",
from = "Column::RecordHeaderId",
to = "super::record_header::Column::Id"
)]
RecordHeader,
#[sea_orm(
belongs_to = "super::record_tag::Entity",
from = "Column::RecordTagId",
to = "super::record_tag::Column::Id"
)]
RecordTag,
}
impl Related<super::record_header::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecordHeader.def()
}
}
impl Related<super::record_tag::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecordTag.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,42 @@
use async_graphql::*;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = "record_header")]
#[graphql(concrete(name = "RecordHeader", params()))]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(indexed)]
#[serde(skip_deserializing)]
pub user_id: i32,
pub comment: String,
}
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
pub enum Relation {
#[sea_orm(has_many = "super::record_detail::Entity")]
RecordDetail,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id"
)]
User,
}
impl Related<super::record_detail::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecordDetail.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,43 @@
use async_graphql::*;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = "record_tag")]
#[graphql(concrete(name = "RecordTag", params()))]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(indexed)]
#[serde(skip_deserializing)]
pub user_id: i32,
#[sea_orm(indexed)]
pub name: String,
}
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
pub enum Relation {
#[sea_orm(has_many = "super::record_detail::Entity")]
RecordDetail,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id"
)]
User,
}
impl Related<super::record_detail::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecordDetail.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,36 @@
use async_graphql::*;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = "user")]
#[graphql(concrete(name = "User", params()))]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(unique, indexed)]
pub login_name: String,
}
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
pub enum Relation {
#[sea_orm(has_many = "super::record_header::Entity")]
RecordHeader,
#[sea_orm(has_many = "super::record_tag::Entity")]
RecordTag,
}
impl Related<super::record_header::Entity> for Model {
fn to() -> RelationDef {
Relation::RecordHeader.def()
}
}
impl Related<super::record_tag::Entity> for Model {
fn to() -> RelationDef {
Relation::RecordTag.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -1,4 +1,6 @@
pub mod data; pub mod data;
pub mod entity;
pub mod error;
pub use self::data::Label; pub use self::data::Label;
pub use self::data::Record; pub use self::data::Record;

View file

@ -7,7 +7,5 @@ repository.workspace = true
[dependencies] [dependencies]
dpts-core = {workspace = true} dpts-core = {workspace = true}
anyhow = {workspace = true}
chrono = {workspace = true} chrono = {workspace = true}
clap = {version = "4.5.37", features=["derive"]} clap = {workspace = true, features = ["derive"]}
thiserror = {workspace = true}