]> Untitled Git - lemmy.git/blobdiff - lemmy_db/src/lib.rs
Merge branch 'drone-io-dess' into move_views_to_diesel_drone
[lemmy.git] / lemmy_db / src / lib.rs
index 57ca24eb3c36d07d3866f5b376456bedbc148810..4df69ca432fb9da21e4d20a34a2c7afe4a2ebae4 100644 (file)
@@ -15,28 +15,10 @@ use regex::Regex;
 use serde::{Deserialize, Serialize};
 use std::{env, env::VarError};
 
-pub mod activity;
-pub mod category;
-pub mod comment;
-pub mod comment_report;
-pub mod comment_view;
-pub mod community;
-pub mod community_view;
-pub mod moderator;
-pub mod moderator_views;
-pub mod password_reset_request;
-pub mod post;
-pub mod post_report;
-pub mod post_view;
-pub mod private_message;
-pub mod private_message_view;
+pub mod aggregates;
 pub mod schema;
-pub mod site;
-pub mod site_view;
-pub mod user;
-pub mod user_mention;
-pub mod user_mention_view;
-pub mod user_view;
+pub mod source;
+pub mod views;
 
 pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
 
@@ -128,6 +110,15 @@ pub trait Reportable<T> {
     Self: Sized;
 }
 
+pub trait ApubObject<T> {
+  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn upsert(conn: &PgConnection, user_form: &T) -> Result<Self, Error>
+  where
+    Self: Sized;
+}
+
 pub trait MaybeOptional<T> {
   fn get_optional(self) -> Option<T>;
 }
@@ -144,6 +135,11 @@ impl<T> MaybeOptional<T> for Option<T> {
   }
 }
 
+pub(crate) trait ToSafe {
+  type SafeColumns;
+  fn safe_columns_tuple() -> Self::SafeColumns;
+}
+
 pub fn get_database_url_from_env() -> Result<String, VarError> {
   env::var("LEMMY_DATABASE_URL")
 }
@@ -217,6 +213,14 @@ lazy_static! {
     Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
 }
 
+pub(crate) mod functions {
+  use diesel::sql_types::*;
+
+  sql_function! {
+    fn hot_rank(score: BigInt, time: Timestamp) -> Integer;
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use super::fuzzy_search;