mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-07 21:15:02 +00:00
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
|
extern crate diesel;
|
||
|
use diesel::*;
|
||
|
use diesel::result::Error;
|
||
|
use serde::{Deserialize, Serialize};
|
||
|
|
||
|
table! {
|
||
|
community_view (id) {
|
||
|
id -> Int4,
|
||
|
name -> Varchar,
|
||
|
title -> Varchar,
|
||
|
description -> Nullable<Text>,
|
||
|
category_id -> Int4,
|
||
|
creator_id -> Int4,
|
||
|
published -> Timestamp,
|
||
|
updated -> Nullable<Timestamp>,
|
||
|
creator_name -> Varchar,
|
||
|
category_name -> Varchar,
|
||
|
number_of_subscribers -> BigInt,
|
||
|
number_of_posts -> BigInt,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
|
||
|
#[table_name="community_view"]
|
||
|
pub struct CommunityView {
|
||
|
pub id: i32,
|
||
|
pub name: String,
|
||
|
pub title: String,
|
||
|
pub description: Option<String>,
|
||
|
pub category_id: i32,
|
||
|
pub creator_id: i32,
|
||
|
pub published: chrono::NaiveDateTime,
|
||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||
|
pub creator_name: String,
|
||
|
pub category_name: String,
|
||
|
pub number_of_subscribers: i64,
|
||
|
pub number_of_posts: i64
|
||
|
}
|
||
|
|
||
|
impl CommunityView {
|
||
|
pub fn read(conn: &PgConnection, from_community_id: i32) -> Result<Self, Error> {
|
||
|
use actions::community_view::community_view::dsl::*;
|
||
|
community_view.find(from_community_id).first::<Self>(conn)
|
||
|
}
|
||
|
|
||
|
pub fn list_all(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
||
|
use actions::community_view::community_view::dsl::*;
|
||
|
community_view.load::<Self>(conn)
|
||
|
}
|
||
|
}
|
||
|
|