1 use crate::{newtypes::DbUrl, source::site::*, traits::Crud};
2 use diesel::{dsl::*, result::Error, *};
8 fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
9 use crate::schema::site::dsl::*;
10 site.first::<Self>(conn)
13 fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
14 use crate::schema::site::dsl::*;
15 insert_into(site).values(new_site).get_result::<Self>(conn)
18 fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
19 use crate::schema::site::dsl::*;
20 diesel::update(site.find(site_id))
22 .get_result::<Self>(conn)
24 fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
25 use crate::schema::site::dsl::*;
26 diesel::delete(site.find(site_id)).execute(conn)
31 pub fn read_local_site(conn: &PgConnection) -> Result<Self, Error> {
32 use crate::schema::site::dsl::*;
33 site.order_by(id).first::<Self>(conn)
36 pub fn upsert(conn: &PgConnection, site_form: &SiteForm) -> Result<Site, Error> {
37 use crate::schema::site::dsl::*;
40 .on_conflict(actor_id)
43 .get_result::<Self>(conn)
46 pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
47 use crate::schema::site::dsl::*;
48 let object_id: DbUrl = object_id.into();
51 .filter(actor_id.eq(object_id))
58 pub fn read_remote_sites(conn: &PgConnection) -> Result<Vec<Self>, Error> {
59 use crate::schema::site::dsl::*;
60 site.order_by(id).offset(1).get_results::<Self>(conn)