]> Untitled Git - lemmy.git/blob - server/lemmy_db/src/site_view.rs
Merge remote-tracking branch 'weblate/main' into main
[lemmy.git] / server / lemmy_db / src / site_view.rs
1 use diesel::{result::Error, *};
2 use serde::{Deserialize, 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(
28   Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
29 )]
30 #[table_name = "site_view"]
31 pub struct SiteView {
32   pub id: i32,
33   pub name: String,
34   pub description: Option<String>,
35   pub creator_id: i32,
36   pub published: chrono::NaiveDateTime,
37   pub updated: Option<chrono::NaiveDateTime>,
38   pub enable_downvotes: bool,
39   pub open_registration: bool,
40   pub enable_nsfw: bool,
41   pub icon: Option<String>,
42   pub banner: Option<String>,
43   pub creator_name: String,
44   pub creator_preferred_username: Option<String>,
45   pub creator_avatar: Option<String>,
46   pub number_of_users: i64,
47   pub number_of_posts: i64,
48   pub number_of_comments: i64,
49   pub number_of_communities: i64,
50 }
51
52 impl SiteView {
53   pub fn read(conn: &PgConnection) -> Result<Self, Error> {
54     use super::site_view::site_view::dsl::*;
55     site_view.first::<Self>(conn)
56   }
57 }