lemmy/crates/db_schema/src/impls/local_site_rate_limit.rs

34 lines
998 B
Rust
Raw Normal View History

2022-11-09 10:05:00 +00:00
use crate::{
schema::local_site_rate_limit,
source::local_site_rate_limit::{
LocalSiteRateLimit,
LocalSiteRateLimitInsertForm,
LocalSiteRateLimitUpdateForm,
},
2022-11-09 10:05:00 +00:00
utils::{get_conn, DbPool},
};
use diesel::{dsl::insert_into, result::Error};
2022-11-09 10:05:00 +00:00
use diesel_async::RunQueryDsl;
impl LocalSiteRateLimit {
2022-11-09 10:05:00 +00:00
pub async fn read(pool: &DbPool) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
local_site_rate_limit::table.first::<Self>(conn).await
}
2022-11-09 10:05:00 +00:00
pub async fn create(pool: &DbPool, form: &LocalSiteRateLimitInsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(local_site_rate_limit::table)
.values(form)
.get_result::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
}
2022-11-09 10:05:00 +00:00
pub async fn update(pool: &DbPool, form: &LocalSiteRateLimitUpdateForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(local_site_rate_limit::table)
.set(form)
.get_result::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
}
}