mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-09 08:59:21 +00:00
235cc8b228
* Moving settings to Database. - Moves many settings into the database. Fixes #2285 - Adds a local_site and instance table. Fixes #2365 . Fixes #2368 - Separates SQL update an insert forms, to avoid runtime errors. - Adds TypedBuilder to all the SQL forms, instead of default. * Fix weird clippy issue. * Removing extra lines. * Some fixes from suggestions. * Fixing apub tests. * Using instance creation helper function. * Move forms to their own line. * Trying to fix local_site_data, still broken. * Fixing federation tests. * Trying to fix check features 1. * Addressing PR comments. * Adding check_apub to all verify functions.
48 lines
1.6 KiB
Rust
48 lines
1.6 KiB
Rust
use crate::{newtypes::LocalUserId, source::registration_application::*, traits::Crud};
|
|
use diesel::{insert_into, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
|
|
|
|
impl Crud for RegistrationApplication {
|
|
type InsertForm = RegistrationApplicationInsertForm;
|
|
type UpdateForm = RegistrationApplicationUpdateForm;
|
|
type IdType = i32;
|
|
fn create(conn: &mut PgConnection, form: &Self::InsertForm) -> Result<Self, Error> {
|
|
use crate::schema::registration_application::dsl::*;
|
|
insert_into(registration_application)
|
|
.values(form)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
|
|
fn read(conn: &mut PgConnection, id_: Self::IdType) -> Result<Self, Error> {
|
|
use crate::schema::registration_application::dsl::*;
|
|
registration_application.find(id_).first::<Self>(conn)
|
|
}
|
|
|
|
fn update(
|
|
conn: &mut PgConnection,
|
|
id_: Self::IdType,
|
|
form: &Self::UpdateForm,
|
|
) -> Result<Self, Error> {
|
|
use crate::schema::registration_application::dsl::*;
|
|
diesel::update(registration_application.find(id_))
|
|
.set(form)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
|
|
fn delete(conn: &mut PgConnection, id_: Self::IdType) -> Result<usize, Error> {
|
|
use crate::schema::registration_application::dsl::*;
|
|
diesel::delete(registration_application.find(id_)).execute(conn)
|
|
}
|
|
}
|
|
|
|
impl RegistrationApplication {
|
|
pub fn find_by_local_user_id(
|
|
conn: &mut PgConnection,
|
|
local_user_id_: LocalUserId,
|
|
) -> Result<Self, Error> {
|
|
use crate::schema::registration_application::dsl::*;
|
|
registration_application
|
|
.filter(local_user_id.eq(local_user_id_))
|
|
.first::<Self>(conn)
|
|
}
|
|
}
|