40 lines
1001 B
Rust
40 lines
1001 B
Rust
use async_graphql::*;
|
|
use sea_orm::{entity::prelude::*, DeleteMany};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize, SimpleObject)]
|
|
#[sea_orm(table_name = "notes")]
|
|
#[graphql(concrete(name = "Note", params()))]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
#[serde(skip_deserializing)]
|
|
pub id: i32,
|
|
pub title: String,
|
|
pub text: String,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
pub enum Relation {}
|
|
|
|
impl RelationTrait for Relation {
|
|
fn def(&self) -> RelationDef {
|
|
panic!("No RelationDef")
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|
|
|
|
impl Entity {
|
|
pub fn find_by_id(id: i32) -> Select<Entity> {
|
|
Self::find().filter(Column::Id.eq(id))
|
|
}
|
|
|
|
pub fn find_by_title(title: &str) -> Select<Entity> {
|
|
Self::find().filter(Column::Title.eq(title))
|
|
}
|
|
|
|
pub fn delete_by_id(id: i32) -> DeleteMany<Entity> {
|
|
Self::delete_many().filter(Column::Id.eq(id))
|
|
}
|
|
}
|