lemmy/crates/db_views/src/site_view.rs

21 lines
558 B
Rust
Raw Normal View History

use crate::structs::SiteView;
2020-12-02 19:32:47 +00:00
use diesel::{result::Error, *};
use lemmy_db_schema::{
aggregates::structs::SiteAggregates,
schema::{site, site_aggregates},
source::site::Site,
2020-12-02 19:32:47 +00:00
};
impl SiteView {
2022-03-08 12:52:33 +00:00
pub fn read_local(conn: &PgConnection) -> Result<Self, Error> {
let (mut site, counts) = site::table
.inner_join(site_aggregates::table)
.select((site::all_columns, site_aggregates::all_columns))
2022-03-08 12:52:33 +00:00
.order_by(site::id)
.first::<(Site, SiteAggregates)>(conn)?;
2020-12-02 19:32:47 +00:00
site.private_key = None;
Ok(SiteView { site, counts })
2020-12-02 19:32:47 +00:00
}
}