2020-05-16 14:04:08 +00:00
|
|
|
use diesel::{result::Error, *};
|
2020-09-14 15:29:50 +00:00
|
|
|
use serde::Serialize;
|
2019-12-11 20:21:47 +00:00
|
|
|
|
|
|
|
table! {
|
|
|
|
site_view (id) {
|
|
|
|
id -> Int4,
|
|
|
|
name -> Varchar,
|
|
|
|
description -> Nullable<Text>,
|
|
|
|
creator_id -> Int4,
|
|
|
|
published -> Timestamp,
|
|
|
|
updated -> Nullable<Timestamp>,
|
|
|
|
enable_downvotes -> Bool,
|
|
|
|
open_registration -> Bool,
|
|
|
|
enable_nsfw -> Bool,
|
2020-08-05 16:03:46 +00:00
|
|
|
icon -> Nullable<Text>,
|
|
|
|
banner -> Nullable<Text>,
|
2019-12-11 20:21:47 +00:00
|
|
|
creator_name -> Varchar,
|
2020-08-05 16:03:46 +00:00
|
|
|
creator_preferred_username -> Nullable<Varchar>,
|
2019-12-29 20:39:48 +00:00
|
|
|
creator_avatar -> Nullable<Text>,
|
2019-12-11 20:21:47 +00:00
|
|
|
number_of_users -> BigInt,
|
|
|
|
number_of_posts -> BigInt,
|
|
|
|
number_of_comments -> BigInt,
|
|
|
|
number_of_communities -> BigInt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 15:29:50 +00:00
|
|
|
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
|
2019-12-11 20:21:47 +00:00
|
|
|
#[table_name = "site_view"]
|
|
|
|
pub struct SiteView {
|
|
|
|
pub id: i32,
|
|
|
|
pub name: String,
|
|
|
|
pub description: Option<String>,
|
|
|
|
pub creator_id: i32,
|
|
|
|
pub published: chrono::NaiveDateTime,
|
|
|
|
pub updated: Option<chrono::NaiveDateTime>,
|
|
|
|
pub enable_downvotes: bool,
|
|
|
|
pub open_registration: bool,
|
|
|
|
pub enable_nsfw: bool,
|
2020-08-05 16:03:46 +00:00
|
|
|
pub icon: Option<String>,
|
|
|
|
pub banner: Option<String>,
|
2019-12-11 20:21:47 +00:00
|
|
|
pub creator_name: String,
|
2020-08-05 16:03:46 +00:00
|
|
|
pub creator_preferred_username: Option<String>,
|
2019-12-29 20:39:48 +00:00
|
|
|
pub creator_avatar: Option<String>,
|
2019-12-11 20:21:47 +00:00
|
|
|
pub number_of_users: i64,
|
|
|
|
pub number_of_posts: i64,
|
|
|
|
pub number_of_comments: i64,
|
|
|
|
pub number_of_communities: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SiteView {
|
|
|
|
pub fn read(conn: &PgConnection) -> Result<Self, Error> {
|
|
|
|
use super::site_view::site_view::dsl::*;
|
|
|
|
site_view.first::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|