summaryrefslogtreecommitdiffstats
path: root/server/lemmy_db/src/site_view.rs
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-07-11 19:12:56 -0400
committerDessalines <tyhou13@gmx.com>2020-07-11 19:12:56 -0400
commit60288b2d060ba930fe6cae22c4824d88fe7a00c9 (patch)
tree8fed01325853240c69f3688ee621be29bedfd382 /server/lemmy_db/src/site_view.rs
parent1710844a1bc6a4f46eceaa12f2fb428cb794c694 (diff)
parent1b9f2fa5f7f7831f59b24cb36a5607a769a0d92e (diff)
Merge branch 'master' into jmarthernandez-remove-karma-from-search
Diffstat (limited to 'server/lemmy_db/src/site_view.rs')
-rw-r--r--server/lemmy_db/src/site_view.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/lemmy_db/src/site_view.rs b/server/lemmy_db/src/site_view.rs
new file mode 100644
index 00000000..bb9b54aa
--- /dev/null
+++ b/server/lemmy_db/src/site_view.rs
@@ -0,0 +1,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)
+ }
+}