lemmy/lemmy_db/src/views/site_view.rs

27 lines
583 B
Rust

use crate::{
source::{
site::Site,
user::{UserSafe, User_},
},
ToSafe,
};
use diesel::{result::Error, *};
use lemmy_db_schema::schema::{site, user_};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct SiteView {
pub site: Site,
pub creator: UserSafe,
}
impl SiteView {
pub fn read(conn: &PgConnection) -> Result<Self, Error> {
let (site, creator) = site::table
.inner_join(user_::table)
.select((site::all_columns, User_::safe_columns_tuple()))
.first::<(Site, UserSafe)>(conn)?;
Ok(SiteView { site, creator })
}
}