summaryrefslogtreecommitdiffstats
path: root/server/lemmy_db/src/site_view.rs
blob: bb9b54aa611825eba581ae9f02ae9ea23d636285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use diesel::{result::Error, *};
use serde::{Deserialize, Serialize};

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,
    creator_name -> Varchar,
    creator_avatar -> Nullable<Text>,
    number_of_users -> BigInt,
    number_of_posts -> BigInt,
    number_of_comments -> BigInt,
    number_of_communities -> BigInt,
  }
}

#[derive(
  Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
)]
#[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,
  pub creator_name: String,
  pub creator_avatar: Option<String>,
  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)
  }
}