robson_core/entities/
gateway.rs1use anyhow::Result;
2use sea_orm::entity::prelude::*;
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
11#[sea_orm(table_name = "gateways")]
12pub struct Model {
13 #[sea_orm(primary_key)]
14 pub id: i32,
15 #[sea_orm(unique)]
16 pub name: String,
17}
18
19#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
20pub enum Relation {}
21
22impl ActiveModelBehavior for ActiveModel {}
23
24impl Model {
25 pub async fn find_by_name(db: &DatabaseConnection, name: &str) -> Result<Option<Model>> {
27 Ok(Entity::find().filter(Column::Name.eq(name)).one(db).await?)
28 }
29
30 pub async fn find_by_id(db: &DatabaseConnection, id: i32) -> Result<Option<Model>> {
32 Ok(Entity::find_by_id(id).one(db).await?)
33 }
34
35 pub async fn find_all(db: &DatabaseConnection) -> Result<Vec<Model>> {
37 Ok(Entity::find().all(db).await?)
38 }
39}