mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-02 13:39:21 +00:00
c9f1407429
* Initial commit to bump diesel to 2.0.0-rc.0 and see what happens * Add chrono feature from diesel * db_schema crate is close to building? * Upgrade diesel-derive-newtype * Mostly modifying references to connections to be mutable ones; also used new way to do migrations as suggested by the migration guide; a lot more compiles now, though I can't figure out this tricky ToSql issue at the moment * Running clippy --fix * Trying to fix drone clippy 1 * Fix clippy * Upgrade clux-musl * Trying to fix drone clippy 2 * Trying to fix drone clippy 3 * Trying to fix drone clippy 5 * Adding diesel table aliases, removing sql view hack. Fixes #2101 Co-authored-by: Steven Chu <stevenc1@gmail.com> Co-authored-by: Nutomic <me@nutomic.com>
43 lines
1.5 KiB
Rust
43 lines
1.5 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 Form = RegistrationApplicationForm;
|
|
type IdType = i32;
|
|
fn create(conn: &mut PgConnection, form: &Self::Form) -> 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::Form) -> 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)
|
|
}
|
|
}
|