//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3 use futures::Stream; use sea_orm::{entity::prelude::*, QueryOrder, QuerySelect}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "account")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub user_id: u64, #[sea_orm(primary_key, auto_increment = false)] pub name: String, #[sea_orm(column_type = "Binary(BlobSize::Blob(Some(64)))")] pub salt: Vec, #[sea_orm(column_type = "VarBinary(256)")] pub enc_login: Vec, #[sea_orm(column_type = "VarBinary(256)")] pub enc_password: Vec, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} impl Entity { /// Gets all user's account from DB #[inline] pub async fn get_all( user_id: u64, db: &DatabaseConnection, ) -> crate::Result> + '_> { Self::find() .filter(Column::UserId.eq(user_id)) .stream(db) .await } /// Streams the names of the user accounts #[inline] pub async fn get_names( user_id: u64, db: &DatabaseConnection, ) -> crate::Result> + '_> { Self::find() .select_only() .column(Column::Name) .filter(Column::UserId.eq(user_id)) .order_by_asc(Column::Name) .into_tuple() .stream(db) .await } /// Checks if the account exists #[inline] pub async fn exists( user_id: u64, account_name: impl Into, db: &DatabaseConnection, ) -> crate::Result { let result = Self::find_by_id((user_id, account_name.into())) .select_only() .column(Column::UserId) .into_tuple::() .one(db) .await?; Ok(result.is_some()) } /// Gets the account from the DB #[inline] pub async fn get( user_id: u64, account_name: impl Into, db: &DatabaseConnection, ) -> crate::Result> { Self::find_by_id((user_id, account_name.into())) .one(db) .await } /// Deletes all the user's accounts from DB #[inline] pub async fn delete_all(user_id: u64, db: &DatabaseConnection) -> crate::Result<()> { Self::delete_many() .filter(Column::UserId.eq(user_id)) .exec(db) .await?; Ok(()) } }