]> Untitled Git - lemmy.git/blob - server/lemmy_db/src/site_view.rs
fd15ac7781a1d64849a7b86d80f453e58047bdfe
[lemmy.git] / server / lemmy_db / src / site_view.rs
1 use diesel::{result::Error, *};
2 use serde::Serialize;
3
4 table! {
5   site_view (id) {
6     id -> Int4,
7     name -> Varchar,
8     description -> Nullable<Text>,
9     creator_id -> Int4,
10     published -> Timestamp,
11     updated -> Nullable<Timestamp>,
12     enable_downvotes -> Bool,
13     open_registration -> Bool,
14     enable_nsfw -> Bool,
15     icon -> Nullable<Text>,
16     banner -> Nullable<Text>,
17     creator_name -> Varchar,
18     creator_preferred_username -> Nullable<Varchar>,
19     creator_avatar -> Nullable<Text>,
20     number_of_users -> BigInt,
21     number_of_posts -> BigInt,
22     number_of_comments -> BigInt,
23     number_of_communities -> BigInt,
24   }
25 }
26
27 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
28 #[table_name = "site_view"]
29 pub struct SiteView {
30   pub id: i32,
31   pub name: String,
32   pub description: Option<String>,
33   pub creator_id: i32,
34   pub published: chrono::NaiveDateTime,
35   pub updated: Option<chrono::NaiveDateTime>,
36   pub enable_downvotes: bool,
37   pub open_registration: bool,
38   pub enable_nsfw: bool,
39   pub icon: Option<String>,
40   pub banner: Option<String>,
41   pub creator_name: String,
42   pub creator_preferred_username: Option<String>,
43   pub creator_avatar: Option<String>,
44   pub number_of_users: i64,
45   pub number_of_posts: i64,
46   pub number_of_comments: i64,
47   pub number_of_communities: i64,
48 }
49
50 impl SiteView {
51   pub fn read(conn: &PgConnection) -> Result<Self, Error> {
52     use super::site_view::site_view::dsl::*;
53     site_view.first::<Self>(conn)
54   }
55 }