]> Untitled Git - lemmy.git/commitdiff
Merge crates db_schema and db_queries
authorFelix Ableitner <me@nutomic.com>
Sat, 16 Oct 2021 13:33:38 +0000 (15:33 +0200)
committerFelix Ableitner <me@nutomic.com>
Wed, 20 Oct 2021 10:28:08 +0000 (12:28 +0200)
169 files changed:
Cargo.lock
Cargo.toml
ansible/templates/docker-compose.yml
api_tests/prepare-drone-federation-test.sh
crates/api/Cargo.toml
crates/api/src/comment.rs
crates/api/src/comment_report.rs
crates/api/src/community.rs
crates/api/src/lib.rs
crates/api/src/local_user.rs
crates/api/src/post.rs
crates/api/src/post_report.rs
crates/api/src/private_message.rs
crates/api/src/site.rs
crates/api_common/Cargo.toml
crates/api_common/src/comment.rs
crates/api_common/src/community.rs
crates/api_common/src/lib.rs
crates/api_common/src/person.rs
crates/api_common/src/post.rs
crates/api_common/src/site.rs
crates/api_common/src/websocket.rs
crates/api_crud/Cargo.toml
crates/api_crud/src/comment/create.rs
crates/api_crud/src/comment/delete.rs
crates/api_crud/src/comment/read.rs
crates/api_crud/src/comment/update.rs
crates/api_crud/src/community/create.rs
crates/api_crud/src/community/delete.rs
crates/api_crud/src/community/read.rs
crates/api_crud/src/community/update.rs
crates/api_crud/src/post/create.rs
crates/api_crud/src/post/delete.rs
crates/api_crud/src/post/read.rs
crates/api_crud/src/post/update.rs
crates/api_crud/src/private_message/create.rs
crates/api_crud/src/private_message/delete.rs
crates/api_crud/src/private_message/read.rs
crates/api_crud/src/private_message/update.rs
crates/api_crud/src/site/create.rs
crates/api_crud/src/site/update.rs
crates/api_crud/src/user/create.rs
crates/api_crud/src/user/delete.rs
crates/api_crud/src/user/read.rs
crates/apub/Cargo.toml
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/comment/mod.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/mod.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/undo.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/private_message/create_or_update.rs
crates/apub/src/activities/private_message/delete.rs
crates/apub/src/activities/private_message/undo_delete.rs
crates/apub/src/activities/report.rs
crates/apub/src/activities/voting/mod.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/fetcher/community.rs
crates/apub/src/fetcher/object_id.rs
crates/apub/src/fetcher/search.rs
crates/apub/src/http/comment.rs
crates/apub/src/http/community.rs
crates/apub/src/http/mod.rs
crates/apub/src/http/person.rs
crates/apub/src/http/post.rs
crates/apub/src/lib.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/db_queries/Cargo.toml [deleted file]
crates/db_queries/src/lib.rs [deleted file]
crates/db_queries/src/source/secret.rs [deleted file]
crates/db_schema/Cargo.toml
crates/db_schema/src/aggregates/comment_aggregates.rs [moved from crates/db_queries/src/aggregates/comment_aggregates.rs with 93% similarity]
crates/db_schema/src/aggregates/community_aggregates.rs [moved from crates/db_queries/src/aggregates/community_aggregates.rs with 94% similarity]
crates/db_schema/src/aggregates/mod.rs [moved from crates/db_queries/src/aggregates/mod.rs with 100% similarity]
crates/db_schema/src/aggregates/person_aggregates.rs [moved from crates/db_queries/src/aggregates/person_aggregates.rs with 94% similarity]
crates/db_schema/src/aggregates/post_aggregates.rs [moved from crates/db_queries/src/aggregates/post_aggregates.rs with 94% similarity]
crates/db_schema/src/aggregates/site_aggregates.rs [moved from crates/db_queries/src/aggregates/site_aggregates.rs with 91% similarity]
crates/db_schema/src/impls/activity.rs [moved from crates/db_queries/src/source/activity.rs with 75% similarity]
crates/db_schema/src/impls/comment.rs [moved from crates/db_queries/src/source/comment.rs with 77% similarity]
crates/db_schema/src/impls/comment_report.rs [moved from crates/db_queries/src/source/comment_report.rs with 86% similarity]
crates/db_schema/src/impls/community.rs [moved from crates/db_queries/src/source/community.rs with 75% similarity]
crates/db_schema/src/impls/community_block.rs [moved from crates/db_queries/src/source/community_block.rs with 76% similarity]
crates/db_schema/src/impls/local_user.rs [moved from crates/db_queries/src/source/local_user.rs with 81% similarity]
crates/db_schema/src/impls/mod.rs [moved from crates/db_queries/src/source/mod.rs with 100% similarity]
crates/db_schema/src/impls/moderator.rs [moved from crates/db_queries/src/source/moderator.rs with 87% similarity]
crates/db_schema/src/impls/password_reset_request.rs [moved from crates/db_queries/src/source/password_reset_request.rs with 82% similarity]
crates/db_schema/src/impls/person.rs [moved from crates/db_queries/src/source/person.rs with 68% similarity]
crates/db_schema/src/impls/person_block.rs [moved from crates/db_queries/src/source/person_block.rs with 70% similarity]
crates/db_schema/src/impls/person_mention.rs [moved from crates/db_queries/src/source/person_mention.rs with 77% similarity]
crates/db_schema/src/impls/post.rs [moved from crates/db_queries/src/source/post.rs with 75% similarity]
crates/db_schema/src/impls/post_report.rs [moved from crates/db_queries/src/source/post_report.rs with 85% similarity]
crates/db_schema/src/impls/private_message.rs [moved from crates/db_queries/src/source/private_message.rs with 72% similarity]
crates/db_schema/src/impls/secret.rs [new file with mode: 0644]
crates/db_schema/src/impls/site.rs [moved from crates/db_queries/src/source/site.rs with 55% similarity]
crates/db_schema/src/lib.rs
crates/db_schema/src/newtypes.rs [new file with mode: 0644]
crates/db_schema/src/source/activity.rs
crates/db_schema/src/source/comment.rs
crates/db_schema/src/source/comment_report.rs
crates/db_schema/src/source/community.rs
crates/db_schema/src/source/community_block.rs
crates/db_schema/src/source/local_user.rs
crates/db_schema/src/source/moderator.rs
crates/db_schema/src/source/password_reset_request.rs
crates/db_schema/src/source/person.rs
crates/db_schema/src/source/person_block.rs
crates/db_schema/src/source/person_mention.rs
crates/db_schema/src/source/post.rs
crates/db_schema/src/source/post_report.rs
crates/db_schema/src/source/private_message.rs
crates/db_schema/src/source/site.rs
crates/db_schema/src/traits.rs [new file with mode: 0644]
crates/db_views/Cargo.toml
crates/db_views/src/comment_report_view.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/local_user_view.rs
crates/db_views/src/post_report_view.rs
crates/db_views/src/post_view.rs
crates/db_views/src/private_message_view.rs
crates/db_views/src/site_view.rs
crates/db_views_actor/Cargo.toml
crates/db_views_actor/src/community_block_view.rs
crates/db_views_actor/src/community_follower_view.rs
crates/db_views_actor/src/community_moderator_view.rs
crates/db_views_actor/src/community_person_ban_view.rs
crates/db_views_actor/src/community_view.rs
crates/db_views_actor/src/person_block_view.rs
crates/db_views_actor/src/person_mention_view.rs
crates/db_views_actor/src/person_view.rs
crates/db_views_moderator/Cargo.toml
crates/db_views_moderator/src/mod_add_community_view.rs
crates/db_views_moderator/src/mod_add_view.rs
crates/db_views_moderator/src/mod_ban_from_community_view.rs
crates/db_views_moderator/src/mod_ban_view.rs
crates/db_views_moderator/src/mod_lock_post_view.rs
crates/db_views_moderator/src/mod_remove_comment_view.rs
crates/db_views_moderator/src/mod_remove_community_view.rs
crates/db_views_moderator/src/mod_remove_post_view.rs
crates/db_views_moderator/src/mod_sticky_post_view.rs
crates/db_views_moderator/src/mod_transfer_community_view.rs
crates/routes/Cargo.toml
crates/routes/src/feeds.rs
crates/routes/src/webfinger.rs
crates/utils/src/settings/mod.rs
crates/websocket/Cargo.toml
crates/websocket/src/chat_server.rs
crates/websocket/src/lib.rs
crates/websocket/src/messages.rs
crates/websocket/src/send.rs
docker/dev/docker-compose.yml
docker/federation/docker-compose.yml
docker/prod/docker-compose.yml
src/code_migrations.rs
src/main.rs
src/scheduled_tasks.rs

index d8204367a481ed92b220409e7c8e96afd3f4b0d1..06361214fb601f6c00f36c404a617f63545e1513 100644 (file)
@@ -1668,7 +1668,6 @@ dependencies = [
  "lazy_static",
  "lemmy_api_common",
  "lemmy_apub",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -1697,7 +1696,6 @@ dependencies = [
  "actix-web",
  "chrono",
  "diesel",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -1732,7 +1730,6 @@ dependencies = [
  "lemmy_api_common",
  "lemmy_apub",
  "lemmy_apub_lib",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -1776,7 +1773,6 @@ dependencies = [
  "itertools",
  "lemmy_api_common",
  "lemmy_apub_lib",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -1834,15 +1830,16 @@ dependencies = [
 ]
 
 [[package]]
-name = "lemmy_db_queries"
+name = "lemmy_db_schema"
 version = "0.13.0"
 dependencies = [
  "bcrypt",
  "chrono",
  "diesel",
+ "diesel-derive-newtype",
  "diesel_migrations",
  "lazy_static",
- "lemmy_db_schema",
+ "lemmy_apub_lib",
  "lemmy_utils",
  "log",
  "regex",
@@ -1855,27 +1852,11 @@ dependencies = [
  "url",
 ]
 
-[[package]]
-name = "lemmy_db_schema"
-version = "0.13.0"
-dependencies = [
- "chrono",
- "diesel",
- "diesel-derive-newtype",
- "lemmy_apub_lib",
- "lemmy_utils",
- "log",
- "serde",
- "serde_json",
- "url",
-]
-
 [[package]]
 name = "lemmy_db_views"
 version = "0.13.0"
 dependencies = [
  "diesel",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "log",
  "serde",
@@ -1888,7 +1869,6 @@ name = "lemmy_db_views_actor"
 version = "0.13.0"
 dependencies = [
  "diesel",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "serde",
 ]
@@ -1898,7 +1878,6 @@ name = "lemmy_db_views_moderator"
 version = "0.13.0"
 dependencies = [
  "diesel",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "serde",
 ]
@@ -1918,7 +1897,6 @@ dependencies = [
  "lazy_static",
  "lemmy_api_common",
  "lemmy_apub_lib",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -1954,7 +1932,6 @@ dependencies = [
  "lemmy_api_crud",
  "lemmy_apub",
  "lemmy_apub_lib",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -2020,7 +1997,6 @@ dependencies = [
  "chrono",
  "diesel",
  "lemmy_api_common",
- "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
index 153d9072fe6abd921f4d5ed9d80ad07731e7e16d..c306f762ab7c5929966280ef2e17238c9371d432 100644 (file)
@@ -22,7 +22,6 @@ members = [
     "crates/apub_lib_derive",
     "crates/apub",
     "crates/utils",
-    "crates/db_queries",
     "crates/db_schema",
     "crates/db_views",
     "crates/db_views_actor",
@@ -38,7 +37,6 @@ lemmy_apub = { version = "=0.13.0", path = "./crates/apub" }
 lemmy_apub_lib = { version = "=0.13.0", path = "./crates/apub_lib" }
 lemmy_utils = { version = "=0.13.0", path = "./crates/utils" }
 lemmy_db_schema = { version = "=0.13.0", path = "./crates/db_schema" }
-lemmy_db_queries = { version = "=0.13.0", path = "./crates/db_queries" }
 lemmy_db_views = { version = "=0.13.0", path = "./crates/db_views" }
 lemmy_db_views_moderator = { version = "=0.13.0", path = "./crates/db_views_moderator" }
 lemmy_db_views_actor = { version = "=0.13.0", path = "./crates/db_views_actor" }
index 5b04c28d40d4433d9b68f1cd97457075a3b6495a..0cf89a2bee5f3b7d4bb41671f18085f88f183adb 100644 (file)
@@ -7,7 +7,7 @@ services:
       - "127.0.0.1:8536:8536"
     restart: always
     environment:
-      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
+      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
     volumes:
       - ./lemmy.hjson:/config/config.hjson:ro
     depends_on:
index 6e08ad359cb08e589f475c61d13682da5ea6d4d0..2dbfbe25101e2c801af0b30c3de71efd5af197cf 100755 (executable)
@@ -3,7 +3,7 @@ set -e
 
 export APUB_TESTING_SEND_SYNC=1
 export RUST_BACKTRACE=1
-export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
 
 for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
   psql "${LEMMY_DATABASE_URL}/lemmy" -c "DROP DATABASE IF EXISTS $INSTANCE"
index 04dd87e053d03f4f8f9dbbb1d2f1d8909132d426..8d389308c8115c2e72478fd759c30a6cb9fd11f4 100644 (file)
@@ -15,7 +15,6 @@ doctest = false
 [dependencies]
 lemmy_apub = { version = "=0.13.0", path = "../apub" }
 lemmy_utils = { version = "=0.13.0", path = "../utils" }
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
 lemmy_db_views_moderator = { version = "=0.13.0", path = "../db_views_moderator" }
index 9311d7dc25d82f4cc134c67a8311e6380aefd4bf..d626c2eaeef9986240a51ab15659a84bba8e11b9 100644 (file)
@@ -15,8 +15,11 @@ use lemmy_apub::{
   },
   fetcher::post_or_comment::PostOrComment,
 };
-use lemmy_db_queries::{source::comment::Comment_, Likeable, Saveable};
-use lemmy_db_schema::{source::comment::*, LocalUserId};
+use lemmy_db_schema::{
+  newtypes::LocalUserId,
+  source::comment::*,
+  traits::{Likeable, Saveable},
+};
 use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
index 5d2561dd9bb0976346a121788fba8eb536ae3239..86f636a6b50ee4d25eaeda321763b803d472794f 100644 (file)
@@ -8,8 +8,7 @@ use lemmy_api_common::{
   is_mod_or_admin,
 };
 use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId};
-use lemmy_db_queries::Reportable;
-use lemmy_db_schema::source::comment_report::*;
+use lemmy_db_schema::{source::comment_report::*, traits::Reportable};
 use lemmy_db_views::{
   comment_report_view::{CommentReportQueryBuilder, CommentReportView},
   comment_view::CommentView,
index ccf0edbfdc473c111da7c3300343191144ba8555..5d7317b2a0af8565dc5ec65b856fac298ddd1c28 100644 (file)
@@ -18,22 +18,32 @@ use lemmy_apub::activities::{
   },
   following::{follow::FollowCommunity as FollowCommunityApub, undo::UndoFollowCommunity},
 };
-use lemmy_db_queries::{
-  source::{comment::Comment_, community::CommunityModerator_, post::Post_},
-  Bannable,
-  Blockable,
-  Crud,
-  Followable,
-  Joinable,
-};
-use lemmy_db_schema::source::{
-  comment::Comment,
-  community::*,
-  community_block::{CommunityBlock, CommunityBlockForm},
-  moderator::*,
-  person::Person,
-  post::Post,
-  site::*,
+use lemmy_db_schema::{
+  source::{
+    comment::Comment,
+    community::{
+      Community,
+      CommunityFollower,
+      CommunityFollowerForm,
+      CommunityModerator,
+      CommunityModeratorForm,
+      CommunityPersonBan,
+      CommunityPersonBanForm,
+    },
+    community_block::{CommunityBlock, CommunityBlockForm},
+    moderator::{
+      ModAddCommunity,
+      ModAddCommunityForm,
+      ModBanFromCommunity,
+      ModBanFromCommunityForm,
+      ModTransferCommunity,
+      ModTransferCommunityForm,
+    },
+    person::Person,
+    post::Post,
+    site::Site,
+  },
+  traits::{Bannable, Blockable, Crud, Followable, Joinable},
 };
 use lemmy_db_views::comment_view::CommentQueryBuilder;
 use lemmy_db_views_actor::{
index ccc817616e2aecf7e555f58a9dbd6abb03c09b0b..74a3d3037098a86ddc27110080fb28a1759b894e 100644 (file)
@@ -191,15 +191,14 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
 #[cfg(test)]
 mod tests {
   use lemmy_api_common::check_validator_time;
-  use lemmy_db_queries::{
+  use lemmy_db_schema::{
     establish_unpooled_connection,
-    source::{local_user::LocalUser_, secret::Secret_},
-    Crud,
-  };
-  use lemmy_db_schema::source::{
-    local_user::{LocalUser, LocalUserForm},
-    person::{Person, PersonForm},
-    secret::Secret,
+    source::{
+      local_user::{LocalUser, LocalUserForm},
+      person::{Person, PersonForm},
+      secret::Secret,
+    },
+    traits::Crud,
   };
   use lemmy_utils::{claims::Claims, settings::structs::Settings};
 
index d5a1533f99dd4b5b67a4e41f98c0a766875d74a2..727dd1a5c14c15671d5eb9a838ec17aca06b6c05 100644 (file)
@@ -11,25 +11,10 @@ use lemmy_api_common::{
   password_length_check,
   person::*,
 };
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   diesel_option_overwrite,
   diesel_option_overwrite_to_url,
   from_opt_str_to_opt_enum,
-  source::{
-    comment::Comment_,
-    community::Community_,
-    local_user::LocalUser_,
-    password_reset_request::PasswordResetRequest_,
-    person::Person_,
-    person_mention::PersonMention_,
-    post::Post_,
-    private_message::PrivateMessage_,
-  },
-  Blockable,
-  Crud,
-  SortType,
-};
-use lemmy_db_schema::{
   naive_now,
   source::{
     comment::Comment,
@@ -44,6 +29,8 @@ use lemmy_db_schema::{
     private_message::PrivateMessage,
     site::*,
   },
+  traits::{Blockable, Crud},
+  SortType,
 };
 use lemmy_db_views::{
   comment_report_view::CommentReportView,
index a79a4bb5e252f221baaa3e96019fa217d1a01e2c..60cdafb9a2c63f4fefb7dc03c8ec93c07b7cacf8 100644 (file)
@@ -22,8 +22,10 @@ use lemmy_apub::{
   },
   fetcher::post_or_comment::PostOrComment,
 };
-use lemmy_db_queries::{source::post::Post_, Crud, Likeable, Saveable};
-use lemmy_db_schema::source::{moderator::*, post::*};
+use lemmy_db_schema::{
+  source::{moderator::*, post::*},
+  traits::{Crud, Likeable, Saveable},
+};
 use lemmy_db_views::post_view::PostView;
 use lemmy_utils::{request::fetch_site_metadata, ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
index 5b8b0b656f0d8f47dbcad286864724915d07701a..35a734d441a820c42c4679e68d0a2658f504a4aa 100644 (file)
@@ -14,8 +14,10 @@ use lemmy_api_common::{
   },
 };
 use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId};
-use lemmy_db_queries::Reportable;
-use lemmy_db_schema::source::post_report::{PostReport, PostReportForm};
+use lemmy_db_schema::{
+  source::post_report::{PostReport, PostReportForm},
+  traits::Reportable,
+};
 use lemmy_db_views::{
   post_report_view::{PostReportQueryBuilder, PostReportView},
   post_view::PostView,
index 6be6ba05b19d05a5e45ec5c71617c9df89ce92d8..1c80f44f47f913a36f17494eafe1136b2178644a 100644 (file)
@@ -5,8 +5,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   person::{MarkPrivateMessageAsRead, PrivateMessageResponse},
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
-use lemmy_db_schema::source::private_message::PrivateMessage;
+use lemmy_db_schema::{source::private_message::PrivateMessage, traits::Crud};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperation};
 
index a80dfe66c8db94a71a026a14ccb604689ff0ee93..105412b0e1f760ad51154b304df189f5fb413b7e 100644 (file)
@@ -15,20 +15,16 @@ use lemmy_apub::{
   fetcher::search::{search_by_apub_id, SearchableObjects},
   EndpointType,
 };
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   from_opt_str_to_opt_enum,
-  source::site::Site_,
-  Crud,
+  newtypes::PersonId,
+  source::{moderator::*, site::Site},
+  traits::{Crud, DeleteableOrRemoveable},
   DbPool,
-  DeleteableOrRemoveable,
   ListingType,
   SearchType,
   SortType,
 };
-use lemmy_db_schema::{
-  source::{moderator::*, site::Site},
-  PersonId,
-};
 use lemmy_db_views::{
   comment_view::{CommentQueryBuilder, CommentView},
   post_view::{PostQueryBuilder, PostView},
@@ -450,7 +446,7 @@ impl Perform for TransferSite {
 
     is_admin(&local_user_view)?;
 
-    let read_site = blocking(context.pool(), move |conn| Site::read_simple(conn)).await??;
+    let read_site = blocking(context.pool(), Site::read_simple).await??;
 
     // Make sure user is the creator
     if read_site.creator_id != local_user_view.person.id {
index 261c061c5773f8fa0ef1931b2f759e7e4a084a8c..5672b583eb8c245ab535a9145cf972a2e1604c29 100644 (file)
@@ -13,7 +13,6 @@ path = "src/lib.rs"
 doctest = false
 
 [dependencies]
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
 lemmy_db_views_moderator = { version = "=0.13.0", path = "../db_views_moderator" }
 lemmy_db_views_actor = { version = "=0.13.0", path = "../db_views_actor" }
index 2739b955589b70c80ef5e8432b54306072a2418c..eadbceb2bb0d9234e9e8d26df2e1e89d7b166076 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId};
+use lemmy_db_schema::newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId};
 use lemmy_db_views::{comment_report_view::CommentReportView, comment_view::CommentView};
 use serde::{Deserialize, Serialize};
 
index eea4bc7b3917f2947c407b4f9c5ee1fc92e49f1c..1f32267f3321606772f01c9fa47d294eb8ee8759 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::{CommunityId, PersonId};
+use lemmy_db_schema::newtypes::{CommunityId, PersonId};
 use lemmy_db_views_actor::{
   community_moderator_view::CommunityModeratorView,
   community_view::CommunityView,
index c4b1dd6f5690eaff22117d57a9efa405c31e2350..f28c34b017816c5a7f9b798d21a086ca6237e4a8 100644 (file)
@@ -7,13 +7,8 @@ pub mod websocket;
 
 use crate::site::FederatedInstances;
 use diesel::PgConnection;
-use lemmy_db_queries::{
-  source::{community::Community_, person_block::PersonBlock_, site::Site_},
-  Crud,
-  DbPool,
-  Readable,
-};
 use lemmy_db_schema::{
+  newtypes::{CommunityId, LocalUserId, PersonId, PostId},
   source::{
     comment::Comment,
     community::Community,
@@ -24,10 +19,8 @@ use lemmy_db_schema::{
     secret::Secret,
     site::Site,
   },
-  CommunityId,
-  LocalUserId,
-  PersonId,
-  PostId,
+  traits::{Crud, Readable},
+  DbPool,
 };
 use lemmy_db_views::local_user_view::{LocalUserSettingsView, LocalUserView};
 use lemmy_db_views_actor::{
@@ -394,7 +387,7 @@ pub async fn check_person_block(
 
 pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), LemmyError> {
   if score == -1 {
-    let site = blocking(pool, move |conn| Site::read_simple(conn)).await??;
+    let site = blocking(pool, Site::read_simple).await??;
     if !site.enable_downvotes {
       return Err(ApiError::err_plain("downvotes_disabled").into());
     }
index ce0c1bf80cbd82e05ec6a178a437355aa82fd67c..b93d47eae29c2d9474e77acad7ac2ec388f713ef 100644 (file)
@@ -15,7 +15,7 @@ pub struct Login {
   pub username_or_email: String,
   pub password: String,
 }
-use lemmy_db_schema::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
+use lemmy_db_schema::newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
 
 #[derive(Serialize, Deserialize)]
 pub struct Register {
index 1a53ef5875ab0b06d7b497eb41dd5251d1d6f43d..d4a8c3f521875e23e92d165151ca6bdadd36073a 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::{CommunityId, PostId, PostReportId};
+use lemmy_db_schema::newtypes::{CommunityId, PostId, PostReportId};
 use lemmy_db_views::{
   comment_view::CommentView,
   post_report_view::PostReportView,
index e1e75f9ea3c66759cf49f657e65643baa60e9a1a..db81fce46a78457317204d383888903a13d5633d 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::{CommunityId, PersonId};
+use lemmy_db_schema::newtypes::{CommunityId, PersonId};
 use lemmy_db_views::{
   comment_view::CommentView,
   local_user_view::LocalUserSettingsView,
index f88819cdce77f4962bf6e93494f6e6686a7e471c..5ab94d92da2d54289c934941cf72262f49160b73 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::{CommunityId, PostId};
+use lemmy_db_schema::newtypes::{CommunityId, PostId};
 use serde::{Deserialize, Serialize};
 
 #[derive(Serialize, Deserialize, Debug)]
index 15438aa2e60a5f5c544ef7f79f09324f8806d186..c73591e3e39c1c9423783d91ace245a14f9aa4b6 100644 (file)
@@ -11,7 +11,6 @@ documentation = "https://join-lemmy.org/docs/en/index.html"
 lemmy_apub = { version = "=0.13.0", path = "../apub" }
 lemmy_apub_lib = { version = "=0.13.0", path = "../apub_lib" }
 lemmy_utils = { version = "=0.13.0", path = "../utils" }
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
 lemmy_db_views_moderator = { version = "=0.13.0", path = "../db_views_moderator" }
index 37ecb2f05dff4c0771a440f0f798b1b0b3b57c21..ff2442b15e20f73dec077afdd7e593adc046f873 100644 (file)
@@ -21,12 +21,13 @@ use lemmy_apub::{
   generate_apub_endpoint,
   EndpointType,
 };
-use lemmy_db_queries::{
-  source::{comment::Comment_, person_mention::PersonMention_},
-  Crud,
-  Likeable,
+use lemmy_db_schema::{
+  source::{
+    comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+    person_mention::PersonMention,
+  },
+  traits::{Crud, Likeable},
 };
-use lemmy_db_schema::source::{comment::*, person_mention::PersonMention};
 use lemmy_db_views::comment_view::CommentView;
 use lemmy_utils::{
   utils::{remove_slurs, scrape_text_for_mentions},
index 96e8063d8b63fdfc3aaadfc18058bac2eefbca36..07c920f7cd197e06ae4f5dc2a009a6829de61741 100644 (file)
@@ -9,8 +9,15 @@ use lemmy_api_common::{
   send_local_notifs,
 };
 use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
-use lemmy_db_queries::{source::comment::Comment_, Crud};
-use lemmy_db_schema::source::{comment::*, community::Community, moderator::*, post::Post};
+use lemmy_db_schema::{
+  source::{
+    comment::Comment,
+    community::Community,
+    moderator::{ModRemoveComment, ModRemoveCommentForm},
+    post::Post,
+  },
+  traits::Crud,
+};
 use lemmy_db_views::comment_view::CommentView;
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
index c4d0c394b7f1b82c3a017409f29bdf8f63827a25..490c9670fdacb2f24005faf4a38d33acd7b6cfc6 100644 (file)
@@ -2,7 +2,12 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt};
 use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
+use lemmy_db_schema::{
+  from_opt_str_to_opt_enum,
+  traits::DeleteableOrRemoveable,
+  ListingType,
+  SortType,
+};
 use lemmy_db_views::comment_view::CommentQueryBuilder;
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::LemmyContext;
index b0892c58c538c027a08aa45c63e10ec112645696..7d45b9403389dcb773c07789917af9c09ca4625e 100644 (file)
@@ -13,8 +13,7 @@ use lemmy_apub::activities::{
   comment::create_or_update::CreateOrUpdateComment,
   CreateOrUpdateType,
 };
-use lemmy_db_queries::source::comment::Comment_;
-use lemmy_db_schema::source::comment::*;
+use lemmy_db_schema::source::comment::Comment;
 use lemmy_db_views::comment_view::CommentView;
 use lemmy_utils::{
   utils::{remove_slurs, scrape_text_for_mentions},
index 56d04ce541a1d9d4d481620d804827ac812a7b78..cc0e62db4c47b9bf982d899f91fa5c6bcaa855d9 100644 (file)
@@ -14,17 +14,20 @@ use lemmy_apub::{
   generate_shared_inbox_url,
   EndpointType,
 };
-use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud, Followable, Joinable};
-use lemmy_db_schema::source::{
-  community::{
-    Community,
-    CommunityFollower,
-    CommunityFollowerForm,
-    CommunityForm,
-    CommunityModerator,
-    CommunityModeratorForm,
+use lemmy_db_schema::{
+  diesel_option_overwrite_to_url,
+  source::{
+    community::{
+      Community,
+      CommunityFollower,
+      CommunityFollowerForm,
+      CommunityForm,
+      CommunityModerator,
+      CommunityModeratorForm,
+    },
+    site::Site,
   },
-  site::Site,
+  traits::{Crud, Followable, Joinable},
 };
 use lemmy_db_views_actor::community_view::CommunityView;
 use lemmy_utils::{
index ea1890402ae88988ea42d0e474243147b4de10c3..5f9fbb44e9d3f5b303149cff7dc2404f48cceb76 100644 (file)
@@ -2,10 +2,12 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
 use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
-use lemmy_db_queries::{source::community::Community_, Crud};
-use lemmy_db_schema::source::{
-  community::*,
-  moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
+use lemmy_db_schema::{
+  source::{
+    community::Community,
+    moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
+  },
+  traits::Crud,
 };
 use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
 use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError};
index 9d9bdce00f4f246afc64f33316151eda259ad1fc..3b9405aff55b09e829443833f629af6549a8fd33 100644 (file)
@@ -2,8 +2,13 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
 use lemmy_apub::{build_actor_id_from_shortname, fetcher::object_id::ObjectId, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
-use lemmy_db_schema::source::community::*;
+use lemmy_db_schema::{
+  from_opt_str_to_opt_enum,
+  source::community::Community,
+  traits::DeleteableOrRemoveable,
+  ListingType,
+  SortType,
+};
 use lemmy_db_views_actor::{
   community_moderator_view::CommunityModeratorView,
   community_view::{CommunityQueryBuilder, CommunityView},
index 56fe72838a096ea1ada90516202343db718a9718..f269807b528523d76889072db06a4d5cfb41c0ff 100644 (file)
@@ -6,11 +6,12 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
 };
 use lemmy_apub::activities::community::update::UpdateCommunity;
-use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud};
 use lemmy_db_schema::{
+  diesel_option_overwrite_to_url,
   naive_now,
+  newtypes::PersonId,
   source::community::{Community, CommunityForm},
-  PersonId,
+  traits::Crud,
 };
 use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
 use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError};
index 108205b7c24f043599ec88bfa5926e6092214960..e75999e59517999c05e53ffb51a4c280b13767c6 100644 (file)
@@ -19,8 +19,10 @@ use lemmy_apub::{
   generate_apub_endpoint,
   EndpointType,
 };
-use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
-use lemmy_db_schema::source::post::*;
+use lemmy_db_schema::{
+  source::post::{Post, PostForm, PostLike, PostLikeForm},
+  traits::{Crud, Likeable},
+};
 use lemmy_utils::{
   request::fetch_site_data,
   utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
index 01fa0575b657935cf7d8cda0d3c97322829d5716..1a9044c37adef4d211ea565ed5acee519c6bab0d 100644 (file)
@@ -9,8 +9,14 @@ use lemmy_api_common::{
   post::*,
 };
 use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
-use lemmy_db_queries::{source::post::Post_, Crud};
-use lemmy_db_schema::source::{community::Community, moderator::*, post::*};
+use lemmy_db_schema::{
+  source::{
+    community::Community,
+    moderator::{ModRemovePost, ModRemovePostForm},
+    post::Post,
+  },
+  traits::Crud,
+};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
 
index 76e9548edd0628163ac154e2acae06231e47643c..ee05b7231463dd96ba3b884d1f5c45b88c8c2787 100644 (file)
@@ -2,7 +2,12 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*};
 use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
+use lemmy_db_schema::{
+  from_opt_str_to_opt_enum,
+  traits::DeleteableOrRemoveable,
+  ListingType,
+  SortType,
+};
 use lemmy_db_views::{
   comment_view::CommentQueryBuilder,
   post_view::{PostQueryBuilder, PostView},
index c84901cc8aeb74457419ba341aa92d90a431380c..8c346b882e131c03dc540d8c166c06f60a20c7a7 100644 (file)
@@ -8,8 +8,11 @@ use lemmy_api_common::{
   post::*,
 };
 use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType};
-use lemmy_db_queries::{source::post::Post_, Crud};
-use lemmy_db_schema::{naive_now, source::post::*};
+use lemmy_db_schema::{
+  naive_now,
+  source::post::{Post, PostForm},
+  traits::Crud,
+};
 use lemmy_utils::{
   request::fetch_site_data,
   utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
index d04412f60f3b600bd0447973411367a6e8b4b5e5..9e3351252062ecc365ea181cde72b48cae5e95f9 100644 (file)
@@ -15,8 +15,10 @@ use lemmy_apub::{
   generate_apub_endpoint,
   EndpointType,
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
-use lemmy_db_schema::source::private_message::{PrivateMessage, PrivateMessageForm};
+use lemmy_db_schema::{
+  source::private_message::{PrivateMessage, PrivateMessageForm},
+  traits::Crud,
+};
 use lemmy_db_views::local_user_view::LocalUserView;
 use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
index 70efc903a6b9f213fe4607978d80d5db3c3a8a6a..0c61a09b0635726a6fefb634a6d31db4cf148825 100644 (file)
@@ -9,8 +9,10 @@ use lemmy_apub::activities::private_message::{
   delete::DeletePrivateMessage as DeletePrivateMessageApub,
   undo_delete::UndoDeletePrivateMessage,
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
-use lemmy_db_schema::source::private_message::PrivateMessage;
+use lemmy_db_schema::{
+  source::private_message::PrivateMessage,
+  traits::{Crud, DeleteableOrRemoveable},
+};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
 
index bf119d75c004a48c31550c92dafbf9075a171d09..ae2dc203fce4bfdf98796da1dd0cf3c9f62155dc 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   person::{GetPrivateMessages, PrivateMessagesResponse},
 };
-use lemmy_db_queries::DeleteableOrRemoveable;
+use lemmy_db_schema::traits::DeleteableOrRemoveable;
 use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder;
 use lemmy_utils::{ConnectionId, LemmyError};
 use lemmy_websocket::LemmyContext;
index 7ef2d71da05df30ceb9014f19c4e05295a7ecf76..026a047e22b2fc2f330a92ba4fcbd5481d18b173 100644 (file)
@@ -9,8 +9,7 @@ use lemmy_apub::activities::{
   private_message::create_or_update::CreateOrUpdatePrivateMessage,
   CreateOrUpdateType,
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
-use lemmy_db_schema::source::private_message::PrivateMessage;
+use lemmy_db_schema::{source::private_message::PrivateMessage, traits::Crud};
 use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
 
index 7fdf4d3c836367e119546442dbe8bce19f8fe779..865ade77f298e3935cbcd41caa076a0dab7b8e03 100644 (file)
@@ -7,13 +7,12 @@ use lemmy_api_common::{
   site::*,
   site_description_length_check,
 };
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   diesel_option_overwrite,
   diesel_option_overwrite_to_url,
-  source::site::Site_,
-  Crud,
+  source::site::{Site, SiteForm},
+  traits::Crud,
 };
-use lemmy_db_schema::source::site::{Site, *};
 use lemmy_db_views::site_view::SiteView;
 use lemmy_utils::{
   utils::{check_slurs, check_slurs_opt},
@@ -34,7 +33,7 @@ impl PerformCrud for CreateSite {
   ) -> Result<SiteResponse, LemmyError> {
     let data: &CreateSite = self;
 
-    let read_site = move |conn: &'_ _| Site::read_simple(conn);
+    let read_site = Site::read_simple;
     if blocking(context.pool(), read_site).await?.is_ok() {
       return Err(ApiError::err_plain("site_already_exists").into());
     };
index 192fa669fb260de0bb228f1c3c9931a9613531cb..b6f06e3ad2e342e518eda35bd7258f74b2264482 100644 (file)
@@ -7,15 +7,12 @@ use lemmy_api_common::{
   site::{EditSite, SiteResponse},
   site_description_length_check,
 };
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   diesel_option_overwrite,
   diesel_option_overwrite_to_url,
-  source::site::Site_,
-  Crud,
-};
-use lemmy_db_schema::{
   naive_now,
   source::site::{Site, SiteForm},
+  traits::Crud,
 };
 use lemmy_db_views::site_view::SiteView;
 use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError};
@@ -39,7 +36,7 @@ impl PerformCrud for EditSite {
     // Make sure user is an admin
     is_admin(&local_user_view)?;
 
-    let found_site = blocking(context.pool(), move |conn| Site::read_simple(conn)).await??;
+    let found_site = blocking(context.pool(), Site::read_simple).await??;
 
     let sidebar = diesel_option_overwrite(&data.sidebar);
     let description = diesel_option_overwrite(&data.description);
index b2beeb8ed68e1951d824ce2184368d0f4feb4723..ce37cd6a07ac1dd456368954a7710605e8f81156 100644 (file)
@@ -8,22 +8,24 @@ use lemmy_apub::{
   generate_shared_inbox_url,
   EndpointType,
 };
-use lemmy_db_queries::{
-  source::{local_user::LocalUser_, site::Site_},
-  Crud,
-  Followable,
-  Joinable,
-  ListingType,
-  SortType,
-};
 use lemmy_db_schema::{
+  newtypes::CommunityId,
   source::{
-    community::*,
+    community::{
+      Community,
+      CommunityFollower,
+      CommunityFollowerForm,
+      CommunityForm,
+      CommunityModerator,
+      CommunityModeratorForm,
+    },
     local_user::{LocalUser, LocalUserForm},
-    person::*,
-    site::*,
+    person::{Person, PersonForm},
+    site::Site,
   },
-  CommunityId,
+  traits::{Crud, Followable, Joinable},
+  ListingType,
+  SortType,
 };
 use lemmy_db_views_actor::person_view::PersonViewSafe;
 use lemmy_utils::{
@@ -48,7 +50,7 @@ impl PerformCrud for Register {
     let data: &Register = self;
 
     // Make sure site has open registration
-    if let Ok(site) = blocking(context.pool(), move |conn| Site::read_simple(conn)).await? {
+    if let Ok(site) = blocking(context.pool(), Site::read_simple).await? {
       if !site.open_registration {
         return Err(ApiError::err_plain("registration_closed").into());
       }
index 050f54116c7e3ade4383721c3c174c60b292c9ed..28f42831ed8c078cde6fcd67f4000c01432dc7b4 100644 (file)
@@ -2,8 +2,7 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use bcrypt::verify;
 use lemmy_api_common::{blocking, get_local_user_view_from_jwt, person::*};
-use lemmy_db_queries::source::{comment::Comment_, person::Person_, post::Post_};
-use lemmy_db_schema::source::{comment::Comment, person::*, post::Post};
+use lemmy_db_schema::source::{comment::Comment, person::Person, post::Post};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::LemmyContext;
 
index 7082d5231279d06d52ed8f892958df77f4f9ce21..4eb6771ee55cfc4b4bc974f82ba7f1a8f53e91db 100644 (file)
@@ -2,8 +2,7 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*};
 use lemmy_apub::{build_actor_id_from_shortname, fetcher::object_id::ObjectId, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, SortType};
-use lemmy_db_schema::source::person::*;
+use lemmy_db_schema::{from_opt_str_to_opt_enum, source::person::Person, SortType};
 use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
 use lemmy_db_views_actor::{
   community_moderator_view::CommunityModeratorView,
index 002f842d1c8af3ab1f5b3fcd82f60bd3bdebbcab..2bc69c4a6c9b2b044c5078ecb8fdda524e7f005e 100644 (file)
@@ -15,7 +15,6 @@ doctest = false
 [dependencies]
 lemmy_utils = { version = "=0.13.0", path = "../utils" }
 lemmy_apub_lib = { version = "=0.13.0", path = "../apub_lib" }
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
 lemmy_db_views_actor = { version = "=0.13.0", path = "../db_views_actor" }
index b22c240e6617d0d0c6d32309c5694dd846e445d9..c9b111837692f7395a9a4caf0e0492b2610cb530 100644 (file)
@@ -21,8 +21,10 @@ use lemmy_apub_lib::{
   values::PublicUrl,
   verify::verify_domains_match,
 };
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
+use lemmy_db_schema::{
+  source::{comment::Comment, community::Community, person::Person, post::Post},
+  traits::Crud,
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
 use serde::{Deserialize, Serialize};
index d24ff35ded03f3f9f3366237528d07954f198398..1ac320cb9915f4f1f7207c8c3d4b30a9dfe6a4db 100644 (file)
@@ -7,10 +7,11 @@ use anyhow::anyhow;
 use itertools::Itertools;
 use lemmy_api_common::{blocking, send_local_notifs};
 use lemmy_apub_lib::{traits::ActorType, webfinger::WebfingerResponse};
-use lemmy_db_queries::{Crud, DbPool};
 use lemmy_db_schema::{
+  newtypes::LocalUserId,
   source::{comment::Comment, community::Community, person::Person, post::Post},
-  LocalUserId,
+  traits::Crud,
+  DbPool,
 };
 use lemmy_utils::{
   request::{retry, RecvError},
index 6544976b5f832c41fff14cc2f18e51aec99b8c1d..149b92cd212ed812606f9fe76fec27bfdf32b67e 100644 (file)
@@ -23,10 +23,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::{source::community::CommunityModerator_, Joinable};
-use lemmy_db_schema::source::{
-  community::{Community, CommunityModerator, CommunityModeratorForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityModerator, CommunityModeratorForm},
+    person::Person,
+  },
+  traits::Joinable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index f01c4133b04170e8f0707c9ff82ad1c81986af3d..9b4c3e8137f6c5e122eec9bc95592198a7dd6da0 100644 (file)
@@ -21,16 +21,18 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::{Bannable, Followable};
-use lemmy_db_schema::source::{
-  community::{
-    Community,
-    CommunityFollower,
-    CommunityFollowerForm,
-    CommunityPersonBan,
-    CommunityPersonBanForm,
+use lemmy_db_schema::{
+  source::{
+    community::{
+      Community,
+      CommunityFollower,
+      CommunityFollowerForm,
+      CommunityPersonBan,
+      CommunityPersonBanForm,
+    },
+    person::Person,
   },
-  person::Person,
+  traits::{Bannable, Followable},
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 34db3c44320162e2a1e428b4c0a40a1ce87a5aa0..4f980d01a1e64098d8f3ba6017b2cd03a54580a7 100644 (file)
@@ -24,10 +24,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::Joinable;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityModerator, CommunityModeratorForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityModerator, CommunityModeratorForm},
+    person::Person,
+  },
+  traits::Joinable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 1aadc9634a4e7951b0b96ed1591c13defcf15c52..47cace42ce0cddaaecc930792c55bc54b4a1262d 100644 (file)
@@ -25,10 +25,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::Bannable;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityPersonBan, CommunityPersonBanForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityPersonBan, CommunityPersonBanForm},
+    person::Person,
+  },
+  traits::Bannable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index b71dcc71b6654c191f5f8f08e70da06e4eb2b30b..02b7126ad76423fe93080609ece54f0cf007cbee 100644 (file)
@@ -22,10 +22,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityForm},
+    person::Person,
+  },
+  traits::Crud,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
index 5c0051d793c3a6680b41947085ec6b8f15f2ab41..251a3ffa411e29e99461ecb081e83d656b99dd8d 100644 (file)
@@ -26,23 +26,22 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::{
-  source::{comment::Comment_, community::Community_, post::Post_},
-  Crud,
-};
-use lemmy_db_schema::source::{
-  comment::Comment,
-  community::Community,
-  moderator::{
-    ModRemoveComment,
-    ModRemoveCommentForm,
-    ModRemoveCommunity,
-    ModRemoveCommunityForm,
-    ModRemovePost,
-    ModRemovePostForm,
+use lemmy_db_schema::{
+  source::{
+    comment::Comment,
+    community::Community,
+    moderator::{
+      ModRemoveComment,
+      ModRemoveCommentForm,
+      ModRemoveCommunity,
+      ModRemoveCommunityForm,
+      ModRemovePost,
+      ModRemovePostForm,
+    },
+    person::Person,
+    post::Post,
   },
-  person::Person,
-  post::Post,
+  traits::Crud,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{
index 7f5dfe386ab14e16c884314d5e0567a7e3e98bd1..3a38f2a22b408bee63b050ec3e22d2b1f7325fb8 100644 (file)
@@ -12,7 +12,6 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActorType, ApubObject},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
 use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{
index 37c2afdcb5919906f779ebf0c37684f330ef5887..7a96d430182517ed42604e4363f8635d1063f482 100644 (file)
@@ -27,7 +27,6 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
 use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{
index b70b4b219c882bf4e32d81a6a4ab47cb3a4a2998..bfc9ba315f7c5b45949afb1df44e1b293f322c4b 100644 (file)
@@ -21,10 +21,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
-use lemmy_db_queries::Followable;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityFollower},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityFollower},
+    person::Person,
+  },
+  traits::Followable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 7e0640a1b021365b1e9b3d5a98108965335554a3..c75a08cd12904bf8c03f804f74c68d4614f8dc67 100644 (file)
@@ -21,10 +21,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
-use lemmy_db_queries::Followable;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityFollower, CommunityFollowerForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityFollower, CommunityFollowerForm},
+    person::Person,
+  },
+  traits::Followable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 0c4e4a8bcbc640a4f38e1290034395ae679d8fb7..2699a98c1071077ecab9dc8dec65418ae4556f1c 100644 (file)
@@ -21,10 +21,12 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
-use lemmy_db_queries::Followable;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityFollower, CommunityFollowerForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityFollower, CommunityFollowerForm},
+    person::Person,
+  },
+  traits::Followable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index f1a33668013aa4212d282117de4772d988440f4d..7a1ddc4060e2c378b0f1154afae64acb855f542a 100644 (file)
@@ -21,8 +21,10 @@ use lemmy_apub_lib::{
   values::PublicUrl,
   verify::{verify_domains_match, verify_urls_match},
 };
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
+use lemmy_db_schema::{
+  source::{community::Community, person::Person, post::Post},
+  traits::Crud,
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
 use serde::{Deserialize, Serialize};
index a5f14d52fd936732519589d104224ef4e9c7c902..6b3bc2b620f34a824f18005938ee423d3e764f09 100644 (file)
@@ -12,8 +12,10 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
+use lemmy_db_schema::{
+  source::{person::Person, private_message::PrivateMessage},
+  traits::Crud,
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
 use serde::{Deserialize, Serialize};
index 865cc785bda7be5e4d2b422e8c612793ae886b3a..ded3b3ad4202ba15635b2b42c516f8d07ba1813f 100644 (file)
@@ -16,8 +16,10 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
-use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
+use lemmy_db_schema::{
+  source::{person::Person, private_message::PrivateMessage},
+  traits::Crud,
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
 use serde::{Deserialize, Serialize};
index e609b1e448f600a212c263307e5de12633dcf712..2c5fd0e72d8cb5920dfc555f210f9d2b8af6b27e 100644 (file)
@@ -21,8 +21,10 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   verify::{verify_domains_match, verify_urls_match},
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
-use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
+use lemmy_db_schema::{
+  source::{person::Person, private_message::PrivateMessage},
+  traits::Crud,
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
 use serde::{Deserialize, Serialize};
index c08210b3d0f741daa10e1df2ba770dfbc220ec2e..aee673cfa5beb5a5b00d5bbfdd1ab54ad20a5cfc 100644 (file)
@@ -16,15 +16,15 @@ use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
 };
-use lemmy_db_queries::{Crud, Reportable};
 use lemmy_db_schema::{
+  newtypes::CommunityId,
   source::{
     comment_report::{CommentReport, CommentReportForm},
     community::Community,
     person::Person,
     post_report::{PostReport, PostReportForm},
   },
-  CommunityId,
+  traits::{Crud, Reportable},
 };
 use lemmy_db_views::{comment_report_view::CommentReportView, post_report_view::PostReportView};
 use lemmy_utils::LemmyError;
index 48d44c0eeeac99054728ff436073471c742cb08f..90757eebfeccdc14d74aca007cc9506e64357594 100644 (file)
@@ -1,10 +1,12 @@
 use crate::activities::voting::vote::VoteType;
 use lemmy_api_common::blocking;
-use lemmy_db_queries::Likeable;
-use lemmy_db_schema::source::{
-  comment::{Comment, CommentLike, CommentLikeForm},
-  person::Person,
-  post::{Post, PostLike, PostLikeForm},
+use lemmy_db_schema::{
+  source::{
+    comment::{Comment, CommentLike, CommentLikeForm},
+    person::Person,
+    post::{Post, PostLike, PostLikeForm},
+  },
+  traits::Likeable,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{
index bfb74371d74488ea57b6191f8e440f4ef982a0ef..2c87aa8994ca62a160625cf740eabbbfca09f3ad 100644 (file)
@@ -27,10 +27,10 @@ use lemmy_apub_lib::{
   values::PublicUrl,
   verify::verify_urls_match,
 };
-use lemmy_db_queries::Crud;
 use lemmy_db_schema::{
+  newtypes::CommunityId,
   source::{community::Community, person::Person},
-  CommunityId,
+  traits::Crud,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 4d85375460ec4e012a9f7f967a7d8bc38a1fa488..2463cbc024af7b510a143e349b3f9ebddac890eb 100644 (file)
@@ -18,10 +18,10 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler, ActorType},
   values::PublicUrl,
 };
-use lemmy_db_queries::Crud;
 use lemmy_db_schema::{
+  newtypes::CommunityId,
   source::{community::Community, person::Person},
-  CommunityId,
+  traits::Crud,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 62749f6e39c33d51e7f05fef20c6302995a47484..646f8fcad01497b7bb7941be5b432c95389bb3b7 100644 (file)
@@ -7,10 +7,12 @@ use activitystreams::collection::{CollectionExt, OrderedCollection};
 use anyhow::Context;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{data::Data, traits::ActivityHandler};
-use lemmy_db_queries::Joinable;
-use lemmy_db_schema::source::{
-  community::{Community, CommunityModerator, CommunityModeratorForm},
-  person::Person,
+use lemmy_db_schema::{
+  source::{
+    community::{Community, CommunityModerator, CommunityModeratorForm},
+    person::Person,
+  },
+  traits::Joinable,
 };
 use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
 use lemmy_utils::{location_info, LemmyError};
index 14e983bb381613a45a540dd8f2ca99f5246b6cf5..771c276a5a3210c3c0ac871da3c364f0f54fb210 100644 (file)
@@ -3,8 +3,7 @@ use anyhow::anyhow;
 use diesel::{NotFound, PgConnection};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{traits::ApubObject, APUB_JSON_CONTENT_TYPE};
-use lemmy_db_queries::DbPool;
-use lemmy_db_schema::DbUrl;
+use lemmy_db_schema::{newtypes::DbUrl, DbPool};
 use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
 use reqwest::StatusCode;
index 9fcf5a79ce33e816debd3bc94e3577a0522ea097..d7b9a0bfd4d4613e4f17b650154831f2cc685702 100644 (file)
@@ -11,11 +11,10 @@ use lemmy_apub_lib::{
   traits::ApubObject,
   webfinger::{webfinger_resolve_actor, WebfingerType},
 };
-use lemmy_db_queries::{
-  source::{community::Community_, person::Person_},
+use lemmy_db_schema::{
+  source::{comment::Comment, community::Community, person::Person, post::Post},
   DbPool,
 };
-use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 use serde::Deserialize;
index 4f63d89d3f7671e2777297683afa5a7a59563d6f..769a9dd85340f4fb9b1da69014ea5049f162fa7f 100644 (file)
@@ -5,8 +5,7 @@ use crate::{
 use actix_web::{body::Body, web, web::Path, HttpResponse};
 use diesel::result::Error::NotFound;
 use lemmy_api_common::blocking;
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::{source::comment::Comment, CommentId};
+use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 use serde::Deserialize;
index 3f74b622aade62f324d90de5e65eb63b7efa5631..2094d15d3918f934092b91f642ffc07d889ea68d 100644 (file)
@@ -24,7 +24,6 @@ use activitystreams::{
 use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler};
-use lemmy_db_queries::source::{activity::Activity_, community::Community_};
 use lemmy_db_schema::source::{activity::Activity, community::Community};
 use lemmy_db_views_actor::{
   community_follower_view::CommunityFollowerView,
index f9c0d2740ebfa7f93431acce8b053dce8ba8e74a..b82a6d890ce83ff9d0507fe37bf4480562620bd7 100644 (file)
@@ -24,8 +24,7 @@ use lemmy_apub_lib::{
   traits::{ActivityFields, ActivityHandler},
   APUB_JSON_CONTENT_TYPE,
 };
-use lemmy_db_queries::{source::activity::Activity_, DbPool};
-use lemmy_db_schema::source::activity::Activity;
+use lemmy_db_schema::{source::activity::Activity, DbPool};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
 use log::{info, trace};
index e84ab2de0a1c5d1c9d6a93df138e6893589610d5..36b6b7d9da59ca51c21884454e1e2ea9b8ab7aac 100644 (file)
@@ -25,7 +25,6 @@ use activitystreams::{
 use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler};
-use lemmy_db_queries::source::person::Person_;
 use lemmy_db_schema::source::person::Person;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 324bb7da9a5d31019042b8d92a6fc6eb50fb2644..c5f22d01ccf5b2dda419efc40fd057a2840845c6 100644 (file)
@@ -5,8 +5,7 @@ use crate::{
 use actix_web::{body::Body, web, HttpResponse};
 use diesel::result::Error::NotFound;
 use lemmy_api_common::blocking;
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::{source::post::Post, PostId};
+use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 use serde::Deserialize;
index 2162b644ce5557037ceac835ff6f194041b9ba04..cc9d5f4875ee97beb11d9768c7dda00976f4b6eb 100644 (file)
@@ -9,11 +9,10 @@ use crate::fetcher::post_or_comment::PostOrComment;
 use anyhow::{anyhow, Context};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{activity_queue::send_activity, traits::ActorType};
-use lemmy_db_queries::{source::activity::Activity_, DbPool};
 use lemmy_db_schema::{
+  newtypes::{CommunityId, DbUrl},
   source::{activity::Activity, person::Person},
-  CommunityId,
-  DbUrl,
+  DbPool,
 };
 use lemmy_db_views_actor::community_person_ban_view::CommunityPersonBanView;
 use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
index f47c11bfb039f4c4f967e030f3e94ba5bb3fe1ad..1748af791a2216434a710472ed75428b357460c8 100644 (file)
@@ -20,15 +20,16 @@ use lemmy_apub_lib::{
   values::{MediaTypeHtml, MediaTypeMarkdown, PublicUrl},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::{source::comment::Comment_, Crud, DbPool};
 use lemmy_db_schema::{
+  newtypes::CommentId,
   source::{
     comment::{Comment, CommentForm},
     community::Community,
     person::Person,
     post::Post,
   },
-  CommentId,
+  traits::Crud,
+  DbPool,
 };
 use lemmy_utils::{
   location_info,
index 4087383abbb8c8f918e396e0508fd3e9e74c0aef..324ae259c88450c0c81b5a773b8f594169cf02c7 100644 (file)
@@ -23,10 +23,10 @@ use lemmy_apub_lib::{
   values::{MediaTypeHtml, MediaTypeMarkdown},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::{source::community::Community_, DbPool};
 use lemmy_db_schema::{
   naive_now,
   source::community::{Community, CommunityForm},
+  DbPool,
 };
 use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
 use lemmy_utils::{
index b05a944cd9f392e38e1170ad5f4ae95426558b39..b558902faa427ea8486ea6c4bdc5b0d1a04f50c7 100644 (file)
@@ -5,7 +5,7 @@ use activitystreams::{
 use anyhow::anyhow;
 use chrono::NaiveDateTime;
 use lemmy_apub_lib::values::MediaTypeMarkdown;
-use lemmy_db_queries::DbPool;
+use lemmy_db_schema::DbPool;
 use lemmy_utils::{utils::convert_datetime, LemmyError};
 use lemmy_websocket::LemmyContext;
 use url::Url;
index 73e34794fcaabe4c14860b5dc0044c435e07eace..45c67f443533a1a2cc5877aaaad8e71e2df94d9c 100644 (file)
@@ -19,10 +19,10 @@ use lemmy_apub_lib::{
   values::{MediaTypeHtml, MediaTypeMarkdown},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::{source::person::Person_, DbPool};
 use lemmy_db_schema::{
   naive_now,
   source::person::{Person as DbPerson, PersonForm},
+  DbPool,
 };
 use lemmy_utils::{
   utils::{check_slurs, check_slurs_opt, convert_datetime, markdown_to_html},
index c18647dd1518d670483b698a8c6856f76d572920..bb301038072deec592e263b1635341f778aba150 100644 (file)
@@ -21,7 +21,6 @@ use lemmy_apub_lib::{
   values::{MediaTypeHtml, MediaTypeMarkdown},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::{source::post::Post_, Crud, DbPool};
 use lemmy_db_schema::{
   self,
   source::{
@@ -29,6 +28,8 @@ use lemmy_db_schema::{
     person::Person,
     post::{Post, PostForm},
   },
+  traits::Crud,
+  DbPool,
 };
 use lemmy_utils::{
   request::fetch_site_data,
index 0a38227727f73b4386abe1b925ecf88e5311f687..8cf40c9e46b8495e16ec90ae0b97595c7bef11c7 100644 (file)
@@ -16,10 +16,13 @@ use lemmy_apub_lib::{
   values::{MediaTypeHtml, MediaTypeMarkdown},
   verify::verify_domains_match,
 };
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DbPool};
-use lemmy_db_schema::source::{
-  person::Person,
-  private_message::{PrivateMessage, PrivateMessageForm},
+use lemmy_db_schema::{
+  source::{
+    person::Person,
+    private_message::{PrivateMessage, PrivateMessageForm},
+  },
+  traits::Crud,
+  DbPool,
 };
 use lemmy_utils::{utils::convert_datetime, LemmyError};
 use lemmy_websocket::LemmyContext;
diff --git a/crates/db_queries/Cargo.toml b/crates/db_queries/Cargo.toml
deleted file mode 100644 (file)
index 6fcd1f8..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-[package]
-name = "lemmy_db_queries"
-version = "0.13.0"
-edition = "2018"
-description = "A link aggregator for the fediverse"
-license = "AGPL-3.0"
-homepage = "https://join-lemmy.org/"
-documentation = "https://join-lemmy.org/docs/en/index.html"
-
-[lib]
-name = "lemmy_db_queries"
-path = "src/lib.rs"
-doctest = false
-
-[dependencies]
-lemmy_utils = { version = "=0.13.0", path = "../utils" }
-lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
-diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
-diesel_migrations = "1.4.0"
-chrono = { version = "0.4.19", features = ["serde"] }
-serde = { version = "1.0.130", features = ["derive"] }
-serde_json = { version = "1.0.68", features = ["preserve_order"] }
-strum = "0.21.0"
-strum_macros = "0.21.1"
-log = "0.4.14"
-sha2 = "0.9.8"
-url = { version = "2.2.2", features = ["serde"] }
-lazy_static = "1.4.0"
-regex = "1.5.4"
-bcrypt = "0.10.1"
-
-[dev-dependencies]
-serial_test = "0.5.1"
diff --git a/crates/db_queries/src/lib.rs b/crates/db_queries/src/lib.rs
deleted file mode 100644 (file)
index aa3c06d..0000000
+++ /dev/null
@@ -1,348 +0,0 @@
-#[macro_use]
-extern crate diesel;
-#[macro_use]
-extern crate strum_macros;
-#[macro_use]
-extern crate lazy_static;
-// this is used in tests
-#[allow(unused_imports)]
-#[macro_use]
-extern crate diesel_migrations;
-
-#[cfg(test)]
-extern crate serial_test;
-
-use diesel::{result::Error, *};
-use lemmy_db_schema::{CommunityId, DbUrl, PersonId};
-use lemmy_utils::ApiError;
-use regex::Regex;
-use serde::{Deserialize, Serialize};
-use std::{env, env::VarError};
-use url::Url;
-
-pub mod aggregates;
-pub mod source;
-
-pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
-
-pub trait Crud {
-  type Form;
-  type IdType;
-  fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn read(conn: &PgConnection, id: Self::IdType) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn update(conn: &PgConnection, id: Self::IdType, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn delete(_conn: &PgConnection, _id: Self::IdType) -> Result<usize, Error>
-  where
-    Self: Sized,
-  {
-    unimplemented!()
-  }
-}
-
-pub trait Followable {
-  type Form;
-  fn follow(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn follow_accepted(
-    conn: &PgConnection,
-    community_id: CommunityId,
-    person_id: PersonId,
-  ) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn unfollow(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
-  where
-    Self: Sized;
-  fn has_local_followers(conn: &PgConnection, community_id: CommunityId) -> Result<bool, Error>;
-}
-
-pub trait Joinable {
-  type Form;
-  fn join(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn leave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait Likeable {
-  type Form;
-  type IdType;
-  fn like(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn remove(
-    conn: &PgConnection,
-    person_id: PersonId,
-    item_id: Self::IdType,
-  ) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait Bannable {
-  type Form;
-  fn ban(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn unban(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait Saveable {
-  type Form;
-  fn save(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn unsave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait Blockable {
-  type Form;
-  fn block(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn unblock(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait Readable {
-  type Form;
-  fn mark_as_read(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn mark_as_unread(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait Reportable {
-  type Form;
-  type IdType;
-  fn report(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
-  where
-    Self: Sized;
-  fn resolve(
-    conn: &PgConnection,
-    report_id: Self::IdType,
-    resolver_id: PersonId,
-  ) -> Result<usize, Error>
-  where
-    Self: Sized;
-  fn unresolve(
-    conn: &PgConnection,
-    report_id: Self::IdType,
-    resolver_id: PersonId,
-  ) -> Result<usize, Error>
-  where
-    Self: Sized;
-}
-
-pub trait DeleteableOrRemoveable {
-  fn blank_out_deleted_or_removed_info(self) -> Self;
-}
-
-pub trait MaybeOptional<T> {
-  fn get_optional(self) -> Option<T>;
-}
-
-impl<T> MaybeOptional<T> for T {
-  fn get_optional(self) -> Option<T> {
-    Some(self)
-  }
-}
-
-impl<T> MaybeOptional<T> for Option<T> {
-  fn get_optional(self) -> Option<T> {
-    self
-  }
-}
-
-pub trait ToSafe {
-  type SafeColumns;
-  fn safe_columns_tuple() -> Self::SafeColumns;
-}
-
-pub trait ToSafeSettings {
-  type SafeSettingsColumns;
-  fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
-}
-
-pub trait ViewToVec {
-  type DbTuple;
-  fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
-  where
-    Self: Sized;
-}
-
-pub fn get_database_url_from_env() -> Result<String, VarError> {
-  env::var("LEMMY_DATABASE_URL")
-}
-
-#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum SortType {
-  Active,
-  Hot,
-  New,
-  TopDay,
-  TopWeek,
-  TopMonth,
-  TopYear,
-  TopAll,
-  MostComments,
-  NewComments,
-}
-
-#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum ListingType {
-  All,
-  Local,
-  Subscribed,
-  Community,
-}
-
-#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum SearchType {
-  All,
-  Comments,
-  Posts,
-  Communities,
-  Users,
-  Url,
-}
-
-pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
-  opt.as_ref().map(|t| T::from_str(t).ok()).flatten()
-}
-
-pub fn fuzzy_search(q: &str) -> String {
-  let replaced = q.replace(" ", "%");
-  format!("%{}%", replaced)
-}
-
-pub fn limit_and_offset(page: Option<i64>, limit: Option<i64>) -> (i64, i64) {
-  let page = page.unwrap_or(1);
-  let limit = limit.unwrap_or(10);
-  let offset = limit * (page - 1);
-  (limit, offset)
-}
-
-pub fn is_email_regex(test: &str) -> bool {
-  EMAIL_REGEX.is_match(test)
-}
-
-pub fn diesel_option_overwrite(opt: &Option<String>) -> Option<Option<String>> {
-  match opt {
-    // An empty string is an erase
-    Some(unwrapped) => {
-      if !unwrapped.eq("") {
-        Some(Some(unwrapped.to_owned()))
-      } else {
-        Some(None)
-      }
-    }
-    None => None,
-  }
-}
-
-pub fn diesel_option_overwrite_to_url(
-  opt: &Option<String>,
-) -> Result<Option<Option<DbUrl>>, ApiError> {
-  match opt.as_ref().map(|s| s.as_str()) {
-    // An empty string is an erase
-    Some("") => Ok(Some(None)),
-    Some(str_url) => match Url::parse(str_url) {
-      Ok(url) => Ok(Some(Some(url.into()))),
-      Err(e) => Err(ApiError::err("invalid_url", e)),
-    },
-    None => Ok(None),
-  }
-}
-
-embed_migrations!();
-
-pub fn establish_unpooled_connection() -> PgConnection {
-  let db_url = match get_database_url_from_env() {
-    Ok(url) => url,
-    Err(e) => panic!(
-      "Failed to read database URL from env var LEMMY_DATABASE_URL: {}",
-      e
-    ),
-  };
-  let conn =
-    PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
-  embedded_migrations::run(&conn).expect("load migrations");
-  conn
-}
-
-lazy_static! {
-  static ref EMAIL_REGEX: Regex =
-    Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
-      .expect("compile email regex");
-}
-
-pub mod functions {
-  use diesel::sql_types::*;
-
-  sql_function! {
-    fn hot_rank(score: BigInt, time: Timestamp) -> Integer;
-  }
-}
-
-#[cfg(test)]
-mod tests {
-  use super::{fuzzy_search, *};
-  use crate::is_email_regex;
-
-  #[test]
-  fn test_fuzzy_search() {
-    let test = "This is a fuzzy search";
-    assert_eq!(fuzzy_search(test), "%This%is%a%fuzzy%search%".to_string());
-  }
-
-  #[test]
-  fn test_email() {
-    assert!(is_email_regex("gush@gmail.com"));
-    assert!(!is_email_regex("nada_neutho"));
-  }
-
-  #[test]
-  fn test_diesel_option_overwrite() {
-    assert_eq!(diesel_option_overwrite(&None), None);
-    assert_eq!(diesel_option_overwrite(&Some("".to_string())), Some(None));
-    assert_eq!(
-      diesel_option_overwrite(&Some("test".to_string())),
-      Some(Some("test".to_string()))
-    );
-  }
-
-  #[test]
-  fn test_diesel_option_overwrite_to_url() {
-    assert!(matches!(diesel_option_overwrite_to_url(&None), Ok(None)));
-    assert!(matches!(
-      diesel_option_overwrite_to_url(&Some("".to_string())),
-      Ok(Some(None))
-    ));
-    assert!(matches!(
-      diesel_option_overwrite_to_url(&Some("invalid_url".to_string())),
-      Err(_)
-    ));
-    let example_url = "https://example.com";
-    assert!(matches!(
-      diesel_option_overwrite_to_url(&Some(example_url.to_string())),
-      Ok(Some(Some(url))) if url == Url::parse(example_url).unwrap().into()
-    ));
-  }
-}
diff --git a/crates/db_queries/src/source/secret.rs b/crates/db_queries/src/source/secret.rs
deleted file mode 100644 (file)
index 6181549..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-use diesel::{result::Error, *};
-use lemmy_db_schema::source::secret::Secret;
-
-pub trait Secret_ {
-  fn init(conn: &PgConnection) -> Result<Secret, Error>;
-}
-
-impl Secret_ for Secret {
-  /// Initialize the Secrets from the DB.
-  /// Warning: You should only call this once.
-  fn init(conn: &PgConnection) -> Result<Secret, Error> {
-    read_secrets(conn)
-  }
-}
-
-fn read_secrets(conn: &PgConnection) -> Result<Secret, Error> {
-  use lemmy_db_schema::schema::secret::dsl::*;
-  secret.first::<Secret>(conn)
-}
index 66b0a293dddc2170dd492865cc3be0f552260a04..a05aed47df15d3baf87396ec870e7ea877bbd185 100644 (file)
@@ -14,9 +14,19 @@ doctest = false
 lemmy_utils = { version = "=0.13.0", path = "../utils" }
 lemmy_apub_lib = { version = "=0.13.0", path = "../apub_lib" }
 diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
+diesel_migrations = "1.4.0"
 chrono = { version = "0.4.19", features = ["serde"] }
 serde = { version = "1.0.130", features = ["derive"] }
 serde_json = { version = "1.0.68", features = ["preserve_order"] }
 log = "0.4.14"
 url = { version = "2.2.2", features = ["serde"] }
 diesel-derive-newtype = "0.1.2"
+regex = "1.5.4"
+lazy_static = "1.4.0"
+strum = "0.21.0"
+strum_macros = "0.21.1"
+sha2 = "0.9.8"
+bcrypt = "0.10.1"
+
+[dev-dependencies]
+serial_test = "0.5.1"
\ No newline at end of file
similarity index 93%
rename from crates/db_queries/src/aggregates/comment_aggregates.rs
rename to crates/db_schema/src/aggregates/comment_aggregates.rs
index 4fbc646b186d06803d5e04bb7cdca0d997feed0e..d47899bbffb11f766008faa19ba9b8b401c27011 100644 (file)
@@ -1,5 +1,5 @@
+use crate::{newtypes::CommentId, schema::comment_aggregates};
 use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::comment_aggregates, CommentId};
 use serde::{Deserialize, Serialize};
 
 #[derive(
@@ -28,14 +28,13 @@ mod tests {
   use crate::{
     aggregates::comment_aggregates::CommentAggregates,
     establish_unpooled_connection,
-    Crud,
-    Likeable,
-  };
-  use lemmy_db_schema::source::{
-    comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
-    community::{Community, CommunityForm},
-    person::{Person, PersonForm},
-    post::{Post, PostForm},
+    source::{
+      comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+      community::{Community, CommunityForm},
+      person::{Person, PersonForm},
+      post::{Post, PostForm},
+    },
+    traits::{Crud, Likeable},
   };
   use serial_test::serial;
 
similarity index 94%
rename from crates/db_queries/src/aggregates/community_aggregates.rs
rename to crates/db_schema/src/aggregates/community_aggregates.rs
index d8865d409ab568fee966fdb9be265c92032ff362..d80425e1731245b7daf92071573fb75a69ff9418 100644 (file)
@@ -1,5 +1,5 @@
+use crate::{newtypes::CommunityId, schema::community_aggregates};
 use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::community_aggregates, CommunityId};
 use serde::{Deserialize, Serialize};
 
 #[derive(
@@ -32,14 +32,13 @@ mod tests {
   use crate::{
     aggregates::community_aggregates::CommunityAggregates,
     establish_unpooled_connection,
-    Crud,
-    Followable,
-  };
-  use lemmy_db_schema::source::{
-    comment::{Comment, CommentForm},
-    community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
-    person::{Person, PersonForm},
-    post::{Post, PostForm},
+    source::{
+      comment::{Comment, CommentForm},
+      community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
+      person::{Person, PersonForm},
+      post::{Post, PostForm},
+    },
+    traits::{Crud, Followable},
   };
   use serial_test::serial;
 
similarity index 94%
rename from crates/db_queries/src/aggregates/person_aggregates.rs
rename to crates/db_schema/src/aggregates/person_aggregates.rs
index 16d480decf94ea0d29bef1ea100a7ba182cdb731..344ec27d9aed81c0668fd5e123241266ebe51027 100644 (file)
@@ -1,5 +1,5 @@
+use crate::{newtypes::PersonId, schema::person_aggregates};
 use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::person_aggregates, PersonId};
 use serde::{Deserialize, Serialize};
 
 #[derive(
@@ -28,14 +28,13 @@ mod tests {
   use crate::{
     aggregates::person_aggregates::PersonAggregates,
     establish_unpooled_connection,
-    Crud,
-    Likeable,
-  };
-  use lemmy_db_schema::source::{
-    comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
-    community::{Community, CommunityForm},
-    person::{Person, PersonForm},
-    post::{Post, PostForm, PostLike, PostLikeForm},
+    source::{
+      comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+      community::{Community, CommunityForm},
+      person::{Person, PersonForm},
+      post::{Post, PostForm, PostLike, PostLikeForm},
+    },
+    traits::{Crud, Likeable},
   };
   use serial_test::serial;
 
similarity index 94%
rename from crates/db_queries/src/aggregates/post_aggregates.rs
rename to crates/db_schema/src/aggregates/post_aggregates.rs
index 323b55ab69492bf53adb5b0186971540ba0d6d97..cb8aba26eca10822bee2c9d398b70a3eb72c28d0 100644 (file)
@@ -1,5 +1,5 @@
+use crate::{newtypes::PostId, schema::post_aggregates};
 use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::post_aggregates, PostId};
 use serde::{Deserialize, Serialize};
 
 #[derive(
@@ -32,14 +32,13 @@ mod tests {
   use crate::{
     aggregates::post_aggregates::PostAggregates,
     establish_unpooled_connection,
-    Crud,
-    Likeable,
-  };
-  use lemmy_db_schema::source::{
-    comment::{Comment, CommentForm},
-    community::{Community, CommunityForm},
-    person::{Person, PersonForm},
-    post::{Post, PostForm, PostLike, PostLikeForm},
+    source::{
+      comment::{Comment, CommentForm},
+      community::{Community, CommunityForm},
+      person::{Person, PersonForm},
+      post::{Post, PostForm, PostLike, PostLikeForm},
+    },
+    traits::{Crud, Likeable},
   };
   use serial_test::serial;
 
similarity index 91%
rename from crates/db_queries/src/aggregates/site_aggregates.rs
rename to crates/db_schema/src/aggregates/site_aggregates.rs
index af0f7cb4d69c1d58dcd503d9f3786080b5c7d9d4..4b4b6c4323c5abb63d3379f4c6c980247909caf6 100644 (file)
@@ -1,5 +1,5 @@
+use crate::schema::site_aggregates;
 use diesel::{result::Error, *};
-use lemmy_db_schema::schema::site_aggregates;
 use serde::{Deserialize, Serialize};
 
 #[derive(
@@ -27,13 +27,17 @@ impl SiteAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{aggregates::site_aggregates::SiteAggregates, establish_unpooled_connection, Crud};
-  use lemmy_db_schema::source::{
-    comment::{Comment, CommentForm},
-    community::{Community, CommunityForm},
-    person::{Person, PersonForm},
-    post::{Post, PostForm},
-    site::{Site, SiteForm},
+  use crate::{
+    aggregates::site_aggregates::SiteAggregates,
+    establish_unpooled_connection,
+    source::{
+      comment::{Comment, CommentForm},
+      community::{Community, CommunityForm},
+      person::{Person, PersonForm},
+      post::{Post, PostForm},
+      site::{Site, SiteForm},
+    },
+    traits::Crud,
   };
   use serial_test::serial;
 
similarity index 75%
rename from crates/db_queries/src/source/activity.rs
rename to crates/db_schema/src/impls/activity.rs
index 3008c38f84df6912fe81a8dc37b9835691a6c9b8..4f1cfd2dd65f6e311eb58023ce5b478a85b663d1 100644 (file)
@@ -1,6 +1,5 @@
-use crate::Crud;
+use crate::{newtypes::DbUrl, source::activity::*, traits::Crud};
 use diesel::{dsl::*, result::Error, sql_types::Text, *};
-use lemmy_db_schema::{source::activity::*, DbUrl};
 use serde::Serialize;
 use serde_json::Value;
 use std::{
@@ -12,12 +11,12 @@ impl Crud for Activity {
   type Form = ActivityForm;
   type IdType = i32;
   fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+    use crate::schema::activity::dsl::*;
     activity.find(activity_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+    use crate::schema::activity::dsl::*;
     insert_into(activity)
       .values(new_activity)
       .get_result::<Self>(conn)
@@ -28,40 +27,19 @@ impl Crud for Activity {
     activity_id: i32,
     new_activity: &ActivityForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+    use crate::schema::activity::dsl::*;
     diesel::update(activity.find(activity_id))
       .set(new_activity)
       .get_result::<Self>(conn)
   }
   fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+    use crate::schema::activity::dsl::*;
     diesel::delete(activity.find(activity_id)).execute(conn)
   }
 }
 
-pub trait Activity_ {
-  fn insert<T>(
-    conn: &PgConnection,
-    ap_id: DbUrl,
-    data: &T,
-    local: bool,
-    sensitive: bool,
-  ) -> Result<Activity, IoError>
-  where
-    T: Serialize + Debug;
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error>;
-  fn delete_olds(conn: &PgConnection) -> Result<usize, Error>;
-
-  /// Returns up to 20 activities of type `Announce/Create/Page` from the community
-  fn read_community_outbox(
-    conn: &PgConnection,
-    community_actor_id: &DbUrl,
-  ) -> Result<Vec<Value>, Error>;
-}
-
-impl Activity_ for Activity {
-  fn insert<T>(
+impl Activity {
+  pub fn insert<T>(
     conn: &PgConnection,
     ap_id: DbUrl,
     data: &T,
@@ -88,21 +66,21 @@ impl Activity_ for Activity {
     }
   }
 
-  fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+  pub fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error> {
+    use crate::schema::activity::dsl::*;
     activity.filter(ap_id.eq(object_id)).first::<Self>(conn)
   }
 
-  fn delete_olds(conn: &PgConnection) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+  pub fn delete_olds(conn: &PgConnection) -> Result<usize, Error> {
+    use crate::schema::activity::dsl::*;
     diesel::delete(activity.filter(published.lt(now - 6.months()))).execute(conn)
   }
 
-  fn read_community_outbox(
+  pub fn read_community_outbox(
     conn: &PgConnection,
     community_actor_id: &DbUrl,
   ) -> Result<Vec<Value>, Error> {
-    use lemmy_db_schema::schema::activity::dsl::*;
+    use crate::schema::activity::dsl::*;
     let res: Vec<Value> = activity
       .select(data)
       .filter(
@@ -122,10 +100,13 @@ impl Activity_ for Activity {
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::{establish_unpooled_connection, source::activity::Activity_};
-  use lemmy_db_schema::source::{
-    activity::{Activity, ActivityForm},
-    person::{Person, PersonForm},
+  use crate::{
+    establish_unpooled_connection,
+    newtypes::DbUrl,
+    source::{
+      activity::{Activity, ActivityForm},
+      person::{Person, PersonForm},
+    },
   };
   use serde_json::Value;
   use serial_test::serial;
similarity index 77%
rename from crates/db_queries/src/source/comment.rs
rename to crates/db_schema/src/impls/comment.rs
index 8031131c5c89c10c7e070c253902fa515108ec6e..aa7e25b28bfa07cf56ad2b978c134fad39f32ce2 100644 (file)
@@ -1,7 +1,6 @@
-use crate::{Crud, DeleteableOrRemoveable, Likeable, Saveable};
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
   naive_now,
+  newtypes::{CommentId, DbUrl, PersonId},
   source::comment::{
     Comment,
     CommentForm,
@@ -10,67 +9,32 @@ use lemmy_db_schema::{
     CommentSaved,
     CommentSavedForm,
   },
-  CommentId,
-  DbUrl,
-  PersonId,
+  traits::{Crud, DeleteableOrRemoveable, Likeable, Saveable},
 };
+use chrono::NaiveDateTime;
+use diesel::{dsl::*, result::Error, *};
+use lemmy_apub_lib::traits::ApubObject;
+use lemmy_utils::LemmyError;
+use url::Url;
 
-pub trait Comment_ {
-  fn update_ap_id(
-    conn: &PgConnection,
-    comment_id: CommentId,
-    apub_id: DbUrl,
-  ) -> Result<Comment, Error>;
-  fn permadelete_for_creator(
-    conn: &PgConnection,
-    for_creator_id: PersonId,
-  ) -> Result<Vec<Comment>, Error>;
-  fn update_deleted(
-    conn: &PgConnection,
-    comment_id: CommentId,
-    new_deleted: bool,
-  ) -> Result<Comment, Error>;
-  fn update_removed(
-    conn: &PgConnection,
-    comment_id: CommentId,
-    new_removed: bool,
-  ) -> Result<Comment, Error>;
-  fn update_removed_for_creator(
-    conn: &PgConnection,
-    for_creator_id: PersonId,
-    new_removed: bool,
-  ) -> Result<Vec<Comment>, Error>;
-  fn update_read(
-    conn: &PgConnection,
-    comment_id: CommentId,
-    new_read: bool,
-  ) -> Result<Comment, Error>;
-  fn update_content(
-    conn: &PgConnection,
-    comment_id: CommentId,
-    new_content: &str,
-  ) -> Result<Comment, Error>;
-  fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Comment, Error>;
-}
-
-impl Comment_ for Comment {
-  fn update_ap_id(
+impl Comment {
+  pub fn update_ap_id(
     conn: &PgConnection,
     comment_id: CommentId,
     apub_id: DbUrl,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
 
     diesel::update(comment.find(comment_id))
       .set(ap_id.eq(apub_id))
       .get_result::<Self>(conn)
   }
 
-  fn permadelete_for_creator(
+  pub fn permadelete_for_creator(
     conn: &PgConnection,
     for_creator_id: PersonId,
   ) -> Result<Vec<Self>, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.filter(creator_id.eq(for_creator_id)))
       .set((
         content.eq("*Permananently Deleted*"),
@@ -80,63 +44,63 @@ impl Comment_ for Comment {
       .get_results::<Self>(conn)
   }
 
-  fn update_deleted(
+  pub fn update_deleted(
     conn: &PgConnection,
     comment_id: CommentId,
     new_deleted: bool,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set((deleted.eq(new_deleted), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn update_removed(
+  pub fn update_removed(
     conn: &PgConnection,
     comment_id: CommentId,
     new_removed: bool,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn update_removed_for_creator(
+  pub fn update_removed_for_creator(
     conn: &PgConnection,
     for_creator_id: PersonId,
     new_removed: bool,
   ) -> Result<Vec<Self>, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.filter(creator_id.eq(for_creator_id)))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_results::<Self>(conn)
   }
 
-  fn update_read(
+  pub fn update_read(
     conn: &PgConnection,
     comment_id: CommentId,
     new_read: bool,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set(read.eq(new_read))
       .get_result::<Self>(conn)
   }
 
-  fn update_content(
+  pub fn update_content(
     conn: &PgConnection,
     comment_id: CommentId,
     new_content: &str,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set((content.eq(new_content), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Comment, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+  pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Comment, Error> {
+    use crate::schema::comment::dsl::*;
     insert_into(comment)
       .values(comment_form)
       .on_conflict(ap_id)
@@ -150,17 +114,17 @@ impl Crud for Comment {
   type Form = CommentForm;
   type IdType = CommentId;
   fn read(conn: &PgConnection, comment_id: CommentId) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     comment.find(comment_id).first::<Self>(conn)
   }
 
   fn delete(conn: &PgConnection, comment_id: CommentId) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::delete(comment.find(comment_id)).execute(conn)
   }
 
   fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     insert_into(comment)
       .values(comment_form)
       .get_result::<Self>(conn)
@@ -171,7 +135,7 @@ impl Crud for Comment {
     comment_id: CommentId,
     comment_form: &CommentForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment::dsl::*;
+    use crate::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set(comment_form)
       .get_result::<Self>(conn)
@@ -182,7 +146,7 @@ impl Likeable for CommentLike {
   type Form = CommentLikeForm;
   type IdType = CommentId;
   fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment_like::dsl::*;
+    use crate::schema::comment_like::dsl::*;
     insert_into(comment_like)
       .values(comment_like_form)
       .on_conflict((comment_id, person_id))
@@ -195,7 +159,7 @@ impl Likeable for CommentLike {
     person_id: PersonId,
     comment_id: CommentId,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::comment_like::dsl;
+    use crate::schema::comment_like::dsl;
     diesel::delete(
       dsl::comment_like
         .filter(dsl::comment_id.eq(comment_id))
@@ -208,7 +172,7 @@ impl Likeable for CommentLike {
 impl Saveable for CommentSaved {
   type Form = CommentSavedForm;
   fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment_saved::dsl::*;
+    use crate::schema::comment_saved::dsl::*;
     insert_into(comment_saved)
       .values(comment_saved_form)
       .on_conflict((comment_id, person_id))
@@ -217,7 +181,7 @@ impl Saveable for CommentSaved {
       .get_result::<Self>(conn)
   }
   fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::comment_saved::dsl::*;
+    use crate::schema::comment_saved::dsl::*;
     diesel::delete(
       comment_saved
         .filter(comment_id.eq(comment_saved_form.comment_id))
@@ -234,14 +198,36 @@ impl DeleteableOrRemoveable for Comment {
   }
 }
 
+impl ApubObject for Comment {
+  type DataType = PgConnection;
+
+  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+    None
+  }
+
+  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
+    use crate::schema::comment::dsl::*;
+    let object_id: DbUrl = object_id.into();
+    Ok(comment.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())
+  }
+
+  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
+    Comment::update_deleted(conn, self.id, true)?;
+    Ok(())
+  }
+}
+
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, Crud, Likeable, Saveable};
-  use lemmy_db_schema::source::{
-    comment::*,
-    community::{Community, CommunityForm},
-    person::{Person, PersonForm},
-    post::*,
+  use crate::{
+    establish_unpooled_connection,
+    source::{
+      comment::*,
+      community::{Community, CommunityForm},
+      person::{Person, PersonForm},
+      post::*,
+    },
+    traits::{Crud, Likeable, Saveable},
   };
   use serial_test::serial;
 
similarity index 86%
rename from crates/db_queries/src/source/comment_report.rs
rename to crates/db_schema/src/impls/comment_report.rs
index 10b9d43e8a83d604094c43cbcf58e88a618cbe8a..d32f3ef4025e684b7babb618e8a672267fbd6faa 100644 (file)
@@ -1,11 +1,10 @@
-use crate::Reportable;
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
   naive_now,
+  newtypes::{CommentReportId, PersonId},
   source::comment_report::{CommentReport, CommentReportForm},
-  CommentReportId,
-  PersonId,
+  traits::Reportable,
 };
+use diesel::{dsl::*, result::Error, *};
 
 impl Reportable for CommentReport {
   type Form = CommentReportForm;
@@ -15,7 +14,7 @@ impl Reportable for CommentReport {
   /// * `conn` - the postgres connection
   /// * `comment_report_form` - the filled CommentReportForm to insert
   fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::comment_report::dsl::*;
+    use crate::schema::comment_report::dsl::*;
     insert_into(comment_report)
       .values(comment_report_form)
       .get_result::<Self>(conn)
@@ -31,7 +30,7 @@ impl Reportable for CommentReport {
     report_id: Self::IdType,
     by_resolver_id: PersonId,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::comment_report::dsl::*;
+    use crate::schema::comment_report::dsl::*;
     update(comment_report.find(report_id))
       .set((
         resolved.eq(true),
@@ -51,7 +50,7 @@ impl Reportable for CommentReport {
     report_id: Self::IdType,
     by_resolver_id: PersonId,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::comment_report::dsl::*;
+    use crate::schema::comment_report::dsl::*;
     update(comment_report.find(report_id))
       .set((
         resolved.eq(false),
similarity index 75%
rename from crates/db_queries/src/source/community.rs
rename to crates/db_schema/src/impls/community.rs
index 26e33380a66c6904cf3a82a68b5f977fbe881403..8acce790cd3f7ff50efab572aeea70c03d01c441 100644 (file)
@@ -1,7 +1,6 @@
-use crate::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
   naive_now,
+  newtypes::{CommunityId, DbUrl, PersonId},
   source::community::{
     Community,
     CommunityFollower,
@@ -13,14 +12,16 @@ use lemmy_db_schema::{
     CommunityPersonBanForm,
     CommunitySafe,
   },
-  CommunityId,
-  DbUrl,
-  PersonId,
+  traits::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
 };
+use chrono::NaiveDateTime;
+use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
+use lemmy_apub_lib::traits::{ActorType, ApubObject};
+use lemmy_utils::LemmyError;
+use url::Url;
 
 mod safe_type {
-  use crate::{source::community::Community, ToSafe};
-  use lemmy_db_schema::schema::community::*;
+  use crate::{schema::community::*, source::community::Community, traits::ToSafe};
 
   type Columns = (
     id,
@@ -64,17 +65,17 @@ impl Crud for Community {
   type Form = CommunityForm;
   type IdType = CommunityId;
   fn read(conn: &PgConnection, community_id: CommunityId) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     community.find(community_id).first::<Self>(conn)
   }
 
   fn delete(conn: &PgConnection, community_id: CommunityId) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     diesel::delete(community.find(community_id)).execute(conn)
   }
 
   fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     insert_into(community)
       .values(new_community)
       .get_result::<Self>(conn)
@@ -85,81 +86,61 @@ impl Crud for Community {
     community_id: CommunityId,
     new_community: &CommunityForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     diesel::update(community.find(community_id))
       .set(new_community)
       .get_result::<Self>(conn)
   }
 }
 
-pub trait Community_ {
-  fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error>;
-  fn update_deleted(
-    conn: &PgConnection,
-    community_id: CommunityId,
-    new_deleted: bool,
-  ) -> Result<Community, Error>;
-  fn update_removed(
-    conn: &PgConnection,
-    community_id: CommunityId,
-    new_removed: bool,
-  ) -> Result<Community, Error>;
-  fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
-  fn read_from_followers_url(
-    conn: &PgConnection,
-    followers_url: &DbUrl,
-  ) -> Result<Community, Error>;
-  fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error>;
-}
-
-impl Community_ for Community {
-  fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+impl Community {
+  pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
+    use crate::schema::community::dsl::*;
     community
       .filter(local.eq(true))
       .filter(name.eq(community_name))
       .first::<Self>(conn)
   }
 
-  fn update_deleted(
+  pub fn update_deleted(
     conn: &PgConnection,
     community_id: CommunityId,
     new_deleted: bool,
   ) -> Result<Community, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     diesel::update(community.find(community_id))
       .set((deleted.eq(new_deleted), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn update_removed(
+  pub fn update_removed(
     conn: &PgConnection,
     community_id: CommunityId,
     new_removed: bool,
   ) -> Result<Community, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     diesel::update(community.find(community_id))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+  pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
+    use crate::schema::community::dsl::*;
     community.select(actor_id).distinct().load::<String>(conn)
   }
 
-  fn read_from_followers_url(
+  pub fn read_from_followers_url(
     conn: &PgConnection,
     followers_url_: &DbUrl,
   ) -> Result<Community, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+    use crate::schema::community::dsl::*;
     community
       .filter(followers_url.eq(followers_url_))
       .first::<Self>(conn)
   }
 
-  fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
+  pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
+    use crate::schema::community::dsl::*;
     insert_into(community)
       .values(community_form)
       .on_conflict(actor_id)
@@ -175,7 +156,7 @@ impl Joinable for CommunityModerator {
     conn: &PgConnection,
     community_moderator_form: &CommunityModeratorForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community_moderator::dsl::*;
+    use crate::schema::community_moderator::dsl::*;
     insert_into(community_moderator)
       .values(community_moderator_form)
       .get_result::<Self>(conn)
@@ -185,7 +166,7 @@ impl Joinable for CommunityModerator {
     conn: &PgConnection,
     community_moderator_form: &CommunityModeratorForm,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::community_moderator::dsl::*;
+    use crate::schema::community_moderator::dsl::*;
     diesel::delete(
       community_moderator
         .filter(community_id.eq(community_moderator_form.community_id))
@@ -215,31 +196,20 @@ impl DeleteableOrRemoveable for Community {
   }
 }
 
-pub trait CommunityModerator_ {
-  fn delete_for_community(
-    conn: &PgConnection,
-    for_community_id: CommunityId,
-  ) -> Result<usize, Error>;
-  fn get_person_moderated_communities(
-    conn: &PgConnection,
-    for_person_id: PersonId,
-  ) -> Result<Vec<CommunityId>, Error>;
-}
-
-impl CommunityModerator_ for CommunityModerator {
-  fn delete_for_community(
+impl CommunityModerator {
+  pub fn delete_for_community(
     conn: &PgConnection,
     for_community_id: CommunityId,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::community_moderator::dsl::*;
+    use crate::schema::community_moderator::dsl::*;
     diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
   }
 
-  fn get_person_moderated_communities(
+  pub fn get_person_moderated_communities(
     conn: &PgConnection,
     for_person_id: PersonId,
   ) -> Result<Vec<CommunityId>, Error> {
-    use lemmy_db_schema::schema::community_moderator::dsl::*;
+    use crate::schema::community_moderator::dsl::*;
     community_moderator
       .filter(person_id.eq(for_person_id))
       .select(community_id)
@@ -253,7 +223,7 @@ impl Bannable for CommunityPersonBan {
     conn: &PgConnection,
     community_person_ban_form: &CommunityPersonBanForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community_person_ban::dsl::*;
+    use crate::schema::community_person_ban::dsl::*;
     insert_into(community_person_ban)
       .values(community_person_ban_form)
       .get_result::<Self>(conn)
@@ -263,7 +233,7 @@ impl Bannable for CommunityPersonBan {
     conn: &PgConnection,
     community_person_ban_form: &CommunityPersonBanForm,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::community_person_ban::dsl::*;
+    use crate::schema::community_person_ban::dsl::*;
     diesel::delete(
       community_person_ban
         .filter(community_id.eq(community_person_ban_form.community_id))
@@ -279,7 +249,7 @@ impl Followable for CommunityFollower {
     conn: &PgConnection,
     community_follower_form: &CommunityFollowerForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community_follower::dsl::*;
+    use crate::schema::community_follower::dsl::*;
     insert_into(community_follower)
       .values(community_follower_form)
       .on_conflict((community_id, person_id))
@@ -295,7 +265,7 @@ impl Followable for CommunityFollower {
   where
     Self: Sized,
   {
-    use lemmy_db_schema::schema::community_follower::dsl::*;
+    use crate::schema::community_follower::dsl::*;
     diesel::update(
       community_follower
         .filter(community_id.eq(community_id_))
@@ -308,7 +278,7 @@ impl Followable for CommunityFollower {
     conn: &PgConnection,
     community_follower_form: &CommunityFollowerForm,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::community_follower::dsl::*;
+    use crate::schema::community_follower::dsl::*;
     diesel::delete(
       community_follower
         .filter(community_id.eq(&community_follower_form.community_id))
@@ -319,7 +289,7 @@ impl Followable for CommunityFollower {
   // TODO: this function name only makes sense if you call it with a remote community. for a local
   //       community, it will also return true if only remote followers exist
   fn has_local_followers(conn: &PgConnection, community_id_: CommunityId) -> Result<bool, Error> {
-    use lemmy_db_schema::schema::community_follower::dsl::*;
+    use crate::schema::community_follower::dsl::*;
     diesel::select(exists(
       community_follower.filter(community_id.eq(community_id_)),
     ))
@@ -327,10 +297,66 @@ impl Followable for CommunityFollower {
   }
 }
 
+impl ApubObject for Community {
+  type DataType = PgConnection;
+
+  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+    Some(self.last_refreshed_at)
+  }
+
+  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
+    use crate::schema::community::dsl::*;
+    let object_id: DbUrl = object_id.into();
+    Ok(
+      community
+        .filter(actor_id.eq(object_id))
+        .first::<Self>(conn)
+        .ok(),
+    )
+  }
+
+  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
+    use crate::schema::community::dsl::*;
+    diesel::update(community.find(self.id))
+      .set((deleted.eq(true), updated.eq(naive_now())))
+      .get_result::<Self>(conn)?;
+    Ok(())
+  }
+}
+
+impl ActorType for Community {
+  fn is_local(&self) -> bool {
+    self.local
+  }
+  fn actor_id(&self) -> Url {
+    self.actor_id.to_owned().into()
+  }
+  fn name(&self) -> String {
+    self.name.clone()
+  }
+  fn public_key(&self) -> Option<String> {
+    self.public_key.to_owned()
+  }
+  fn private_key(&self) -> Option<String> {
+    self.private_key.to_owned()
+  }
+
+  fn inbox_url(&self) -> Url {
+    self.inbox_url.clone().into()
+  }
+
+  fn shared_inbox_url(&self) -> Option<Url> {
+    self.shared_inbox_url.clone().map(|s| s.into_inner())
+  }
+}
+
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, Bannable, Crud, Followable, Joinable};
-  use lemmy_db_schema::source::{community::*, person::*};
+  use crate::{
+    establish_unpooled_connection,
+    source::{community::*, person::*},
+    traits::{Bannable, Crud, Followable, Joinable},
+  };
   use serial_test::serial;
 
   #[test]
similarity index 76%
rename from crates/db_queries/src/source/community_block.rs
rename to crates/db_schema/src/impls/community_block.rs
index 346e7f3ac1fceb18e5b9c7db4397195214ceac5e..bbad2f122437fe7936117a77ac5c955a1dc831b8 100644 (file)
@@ -1,11 +1,13 @@
-use crate::Blockable;
+use crate::{
+  source::community_block::{CommunityBlock, CommunityBlockForm},
+  traits::Blockable,
+};
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::source::community_block::{CommunityBlock, CommunityBlockForm};
 
 impl Blockable for CommunityBlock {
   type Form = CommunityBlockForm;
   fn block(conn: &PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::community_block::dsl::*;
+    use crate::schema::community_block::dsl::*;
     insert_into(community_block)
       .values(community_block_form)
       .on_conflict((person_id, community_id))
@@ -14,7 +16,7 @@ impl Blockable for CommunityBlock {
       .get_result::<Self>(conn)
   }
   fn unblock(conn: &PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::community_block::dsl::*;
+    use crate::schema::community_block::dsl::*;
     diesel::delete(
       community_block
         .filter(person_id.eq(community_block_form.person_id))
similarity index 81%
rename from crates/db_queries/src/source/local_user.rs
rename to crates/db_schema/src/impls/local_user.rs
index 91eac3308ecd4c3f2ed92db92cc49b98dcd132aa..3a2d5769517a87a18188b02fc7b1d87ca2f41e4c 100644 (file)
@@ -1,16 +1,19 @@
-use crate::Crud;
-use bcrypt::{hash, DEFAULT_COST};
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
   naive_now,
+  newtypes::LocalUserId,
   schema::local_user::dsl::*,
   source::local_user::{LocalUser, LocalUserForm},
-  LocalUserId,
+  traits::Crud,
 };
+use bcrypt::{hash, DEFAULT_COST};
+use diesel::{dsl::*, result::Error, *};
 
 mod safe_settings_type {
-  use crate::ToSafeSettings;
-  use lemmy_db_schema::{schema::local_user::columns::*, source::local_user::LocalUser};
+  use crate::{
+    schema::local_user::columns::*,
+    source::local_user::LocalUser,
+    traits::ToSafeSettings,
+  };
 
   type Columns = (
     id,
@@ -56,17 +59,8 @@ mod safe_settings_type {
   }
 }
 
-pub trait LocalUser_ {
-  fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<LocalUser, Error>;
-  fn update_password(
-    conn: &PgConnection,
-    local_user_id: LocalUserId,
-    new_password: &str,
-  ) -> Result<LocalUser, Error>;
-}
-
-impl LocalUser_ for LocalUser {
-  fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
+impl LocalUser {
+  pub fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
     let mut edited_user = form.clone();
     let password_hash =
       hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
@@ -75,7 +69,7 @@ impl LocalUser_ for LocalUser {
     Self::create(conn, &edited_user)
   }
 
-  fn update_password(
+  pub fn update_password(
     conn: &PgConnection,
     local_user_id: LocalUserId,
     new_password: &str,
similarity index 87%
rename from crates/db_queries/src/source/moderator.rs
rename to crates/db_schema/src/impls/moderator.rs
index eee5d5e9f2265126489b8928adff960e6823156d..952bab40e767cba01327aad8557514d79a8b446b 100644 (file)
@@ -1,24 +1,23 @@
-use crate::Crud;
+use crate::{source::moderator::*, traits::Crud};
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::source::moderator::*;
 
 impl Crud for ModRemovePost {
   type Form = ModRemovePostForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_post::dsl::*;
+    use crate::schema::mod_remove_post::dsl::*;
     mod_remove_post.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_post::dsl::*;
+    use crate::schema::mod_remove_post::dsl::*;
     insert_into(mod_remove_post)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_post::dsl::*;
+    use crate::schema::mod_remove_post::dsl::*;
     diesel::update(mod_remove_post.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -29,19 +28,19 @@ impl Crud for ModLockPost {
   type Form = ModLockPostForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_lock_post::dsl::*;
+    use crate::schema::mod_lock_post::dsl::*;
     mod_lock_post.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_lock_post::dsl::*;
+    use crate::schema::mod_lock_post::dsl::*;
     insert_into(mod_lock_post)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_lock_post::dsl::*;
+    use crate::schema::mod_lock_post::dsl::*;
     diesel::update(mod_lock_post.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -52,19 +51,19 @@ impl Crud for ModStickyPost {
   type Form = ModStickyPostForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
+    use crate::schema::mod_sticky_post::dsl::*;
     mod_sticky_post.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
+    use crate::schema::mod_sticky_post::dsl::*;
     insert_into(mod_sticky_post)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
+    use crate::schema::mod_sticky_post::dsl::*;
     diesel::update(mod_sticky_post.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -75,19 +74,19 @@ impl Crud for ModRemoveComment {
   type Form = ModRemoveCommentForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
+    use crate::schema::mod_remove_comment::dsl::*;
     mod_remove_comment.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
+    use crate::schema::mod_remove_comment::dsl::*;
     insert_into(mod_remove_comment)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
+    use crate::schema::mod_remove_comment::dsl::*;
     diesel::update(mod_remove_comment.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -98,12 +97,12 @@ impl Crud for ModRemoveCommunity {
   type Form = ModRemoveCommunityForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_community::dsl::*;
+    use crate::schema::mod_remove_community::dsl::*;
     mod_remove_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_community::dsl::*;
+    use crate::schema::mod_remove_community::dsl::*;
     insert_into(mod_remove_community)
       .values(form)
       .get_result::<Self>(conn)
@@ -114,7 +113,7 @@ impl Crud for ModRemoveCommunity {
     from_id: i32,
     form: &ModRemoveCommunityForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_remove_community::dsl::*;
+    use crate::schema::mod_remove_community::dsl::*;
     diesel::update(mod_remove_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -125,12 +124,12 @@ impl Crud for ModBanFromCommunity {
   type Form = ModBanFromCommunityForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
+    use crate::schema::mod_ban_from_community::dsl::*;
     mod_ban_from_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
+    use crate::schema::mod_ban_from_community::dsl::*;
     insert_into(mod_ban_from_community)
       .values(form)
       .get_result::<Self>(conn)
@@ -141,7 +140,7 @@ impl Crud for ModBanFromCommunity {
     from_id: i32,
     form: &ModBanFromCommunityForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
+    use crate::schema::mod_ban_from_community::dsl::*;
     diesel::update(mod_ban_from_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -152,17 +151,17 @@ impl Crud for ModBan {
   type Form = ModBanForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_ban::dsl::*;
+    use crate::schema::mod_ban::dsl::*;
     mod_ban.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_ban::dsl::*;
+    use crate::schema::mod_ban::dsl::*;
     insert_into(mod_ban).values(form).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_ban::dsl::*;
+    use crate::schema::mod_ban::dsl::*;
     diesel::update(mod_ban.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -173,19 +172,19 @@ impl Crud for ModAddCommunity {
   type Form = ModAddCommunityForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_add_community::dsl::*;
+    use crate::schema::mod_add_community::dsl::*;
     mod_add_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_add_community::dsl::*;
+    use crate::schema::mod_add_community::dsl::*;
     insert_into(mod_add_community)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_add_community::dsl::*;
+    use crate::schema::mod_add_community::dsl::*;
     diesel::update(mod_add_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -196,12 +195,12 @@ impl Crud for ModTransferCommunity {
   type Form = ModTransferCommunityForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_transfer_community::dsl::*;
+    use crate::schema::mod_transfer_community::dsl::*;
     mod_transfer_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModTransferCommunityForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_transfer_community::dsl::*;
+    use crate::schema::mod_transfer_community::dsl::*;
     insert_into(mod_transfer_community)
       .values(form)
       .get_result::<Self>(conn)
@@ -212,7 +211,7 @@ impl Crud for ModTransferCommunity {
     from_id: i32,
     form: &ModTransferCommunityForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_transfer_community::dsl::*;
+    use crate::schema::mod_transfer_community::dsl::*;
     diesel::update(mod_transfer_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -223,17 +222,17 @@ impl Crud for ModAdd {
   type Form = ModAddForm;
   type IdType = i32;
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_add::dsl::*;
+    use crate::schema::mod_add::dsl::*;
     mod_add.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_add::dsl::*;
+    use crate::schema::mod_add::dsl::*;
     insert_into(mod_add).values(form).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::mod_add::dsl::*;
+    use crate::schema::mod_add::dsl::*;
     diesel::update(mod_add.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -242,8 +241,11 @@ impl Crud for ModAdd {
 
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, Crud};
-  use lemmy_db_schema::source::{comment::*, community::*, moderator::*, person::*, post::*};
+  use crate::{
+    establish_unpooled_connection,
+    source::{comment::*, community::*, moderator::*, person::*, post::*},
+    traits::Crud,
+  };
   use serial_test::serial;
 
   // use Crud;
similarity index 82%
rename from crates/db_queries/src/source/password_reset_request.rs
rename to crates/db_schema/src/impls/password_reset_request.rs
index a71cdae26481aac14ac3ab2c3d98d2dc3b78aa52..c5debd9262e81ec1825345c55d5e7eff569b0251 100644 (file)
@@ -1,10 +1,10 @@
-use crate::Crud;
-use diesel::{dsl::*, result::Error, PgConnection, *};
-use lemmy_db_schema::{
+use crate::{
+  newtypes::LocalUserId,
   schema::password_reset_request::dsl::*,
   source::password_reset_request::*,
-  LocalUserId,
+  traits::Crud,
 };
+use diesel::{dsl::*, result::Error, PgConnection, *};
 use sha2::{Digest, Sha256};
 
 impl Crud for PasswordResetRequest {
@@ -31,17 +31,8 @@ impl Crud for PasswordResetRequest {
   }
 }
 
-pub trait PasswordResetRequest_ {
-  fn create_token(
-    conn: &PgConnection,
-    from_local_user_id: LocalUserId,
-    token: &str,
-  ) -> Result<PasswordResetRequest, Error>;
-  fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error>;
-}
-
-impl PasswordResetRequest_ for PasswordResetRequest {
-  fn create_token(
+impl PasswordResetRequest {
+  pub fn create_token(
     conn: &PgConnection,
     from_local_user_id: LocalUserId,
     token: &str,
@@ -57,7 +48,7 @@ impl PasswordResetRequest_ for PasswordResetRequest {
 
     Self::create(conn, &form)
   }
-  fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
+  pub fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
     let mut hasher = Sha256::new();
     hasher.update(token);
     let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
@@ -80,13 +71,12 @@ fn bytes_to_hex(bytes: Vec<u8>) -> String {
 mod tests {
   use crate::{
     establish_unpooled_connection,
-    source::password_reset_request::PasswordResetRequest_,
-    Crud,
-  };
-  use lemmy_db_schema::source::{
-    local_user::{LocalUser, LocalUserForm},
-    password_reset_request::PasswordResetRequest,
-    person::*,
+    source::{
+      local_user::{LocalUser, LocalUserForm},
+      password_reset_request::PasswordResetRequest,
+      person::*,
+    },
+    traits::Crud,
   };
   use serial_test::serial;
 
similarity index 68%
rename from crates/db_queries/src/source/person.rs
rename to crates/db_schema/src/impls/person.rs
index 3f0c6f867d9c7e67ed3a7c0dad4f24636fd02f5d..5b7cb941687d788ea1295fd7402ed1b11a6c7c9c 100644 (file)
@@ -1,15 +1,18 @@
-use crate::Crud;
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
   naive_now,
+  newtypes::{DbUrl, PersonId},
   schema::person::dsl::*,
   source::person::{Person, PersonForm},
-  PersonId,
+  traits::Crud,
 };
+use chrono::NaiveDateTime;
+use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl, *};
+use lemmy_apub_lib::traits::{ActorType, ApubObject};
+use lemmy_utils::LemmyError;
+use url::Url;
 
 mod safe_type {
-  use crate::ToSafe;
-  use lemmy_db_schema::{schema::person::columns::*, source::person::Person};
+  use crate::{schema::person::columns::*, source::person::Person, traits::ToSafe};
 
   type Columns = (
     id,
@@ -58,8 +61,7 @@ mod safe_type {
 }
 
 mod safe_type_alias_1 {
-  use crate::ToSafe;
-  use lemmy_db_schema::{schema::person_alias_1::columns::*, source::person::PersonAlias1};
+  use crate::{schema::person_alias_1::columns::*, source::person::PersonAlias1, traits::ToSafe};
 
   type Columns = (
     id,
@@ -108,8 +110,7 @@ mod safe_type_alias_1 {
 }
 
 mod safe_type_alias_2 {
-  use crate::ToSafe;
-  use lemmy_db_schema::{schema::person_alias_2::columns::*, source::person::PersonAlias2};
+  use crate::{schema::person_alias_2::columns::*, source::person::PersonAlias2, traits::ToSafe};
 
   type Columns = (
     id,
@@ -179,29 +180,20 @@ impl Crud for Person {
   }
 }
 
-pub trait Person_ {
-  fn ban_person(conn: &PgConnection, person_id: PersonId, ban: bool) -> Result<Person, Error>;
-  fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Person, Error>;
-  fn find_by_name(conn: &PgConnection, name: &str) -> Result<Person, Error>;
-  fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error>;
-  fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error>;
-  fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result<Person, Error>;
-}
-
-impl Person_ for Person {
-  fn ban_person(conn: &PgConnection, person_id: PersonId, ban: bool) -> Result<Self, Error> {
+impl Person {
+  pub fn ban_person(conn: &PgConnection, person_id: PersonId, ban: bool) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set(banned.eq(ban))
       .get_result::<Self>(conn)
   }
 
-  fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Self, Error> {
+  pub fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set(admin.eq(added))
       .get_result::<Self>(conn)
   }
 
-  fn find_by_name(conn: &PgConnection, from_name: &str) -> Result<Person, Error> {
+  pub fn find_by_name(conn: &PgConnection, from_name: &str) -> Result<Person, Error> {
     person
       .filter(deleted.eq(false))
       .filter(local.eq(true))
@@ -209,14 +201,14 @@ impl Person_ for Person {
       .first::<Person>(conn)
   }
 
-  fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
+  pub fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
     diesel::update(person.find(person_id))
       .set((last_refreshed_at.eq(naive_now()),))
       .get_result::<Self>(conn)
   }
 
-  fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
-    use lemmy_db_schema::schema::local_user;
+  pub fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
+    use crate::schema::local_user;
 
     // Set the local user info to none
     diesel::update(local_user::table.filter(local_user::person_id.eq(person_id)))
@@ -237,7 +229,7 @@ impl Person_ for Person {
       .get_result::<Self>(conn)
   }
 
-  fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
+  pub fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
     insert_into(person)
       .values(person_form)
       .on_conflict(actor_id)
@@ -247,9 +239,65 @@ impl Person_ for Person {
   }
 }
 
+impl ApubObject for Person {
+  type DataType = PgConnection;
+
+  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+    Some(self.last_refreshed_at)
+  }
+
+  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
+    use crate::schema::person::dsl::*;
+    let object_id: DbUrl = object_id.into();
+    Ok(
+      person
+        .filter(deleted.eq(false))
+        .filter(actor_id.eq(object_id))
+        .first::<Self>(conn)
+        .ok(),
+    )
+  }
+
+  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
+    use crate::schema::person::dsl::*;
+    diesel::update(person.find(self.id))
+      .set((deleted.eq(true), updated.eq(naive_now())))
+      .get_result::<Self>(conn)?;
+    Ok(())
+  }
+}
+
+impl ActorType for Person {
+  fn is_local(&self) -> bool {
+    self.local
+  }
+  fn actor_id(&self) -> Url {
+    self.actor_id.to_owned().into_inner()
+  }
+  fn name(&self) -> String {
+    self.name.clone()
+  }
+
+  fn public_key(&self) -> Option<String> {
+    self.public_key.to_owned()
+  }
+
+  fn private_key(&self) -> Option<String> {
+    self.private_key.to_owned()
+  }
+
+  fn inbox_url(&self) -> Url {
+    self.inbox_url.clone().into()
+  }
+
+  fn shared_inbox_url(&self) -> Option<Url> {
+    self.shared_inbox_url.clone().map(|s| s.into_inner())
+  }
+}
+
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, source::person::*};
+  use crate::{establish_unpooled_connection, source::person::*, traits::Crud};
 
   #[test]
   fn test_crud() {
similarity index 70%
rename from crates/db_queries/src/source/person_block.rs
rename to crates/db_schema/src/impls/person_block.rs
index d4505519c33bc11e8f2668355c1ebea055eea693..d1b776805f8ae446d6af48c447cb916a6be2e264 100644 (file)
@@ -1,25 +1,17 @@
-use crate::Blockable;
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
+  newtypes::PersonId,
   source::person_block::{PersonBlock, PersonBlockForm},
-  PersonId,
+  traits::Blockable,
 };
+use diesel::{dsl::*, result::Error, *};
 
-pub trait PersonBlock_ {
-  fn read(
-    conn: &PgConnection,
-    person_id: PersonId,
-    target_id: PersonId,
-  ) -> Result<PersonBlock, Error>;
-}
-
-impl PersonBlock_ for PersonBlock {
-  fn read(
+impl PersonBlock {
+  pub fn read(
     conn: &PgConnection,
     for_person_id: PersonId,
     for_recipient_id: PersonId,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::person_block::dsl::*;
+    use crate::schema::person_block::dsl::*;
     person_block
       .filter(person_id.eq(for_person_id))
       .filter(target_id.eq(for_recipient_id))
@@ -30,7 +22,7 @@ impl PersonBlock_ for PersonBlock {
 impl Blockable for PersonBlock {
   type Form = PersonBlockForm;
   fn block(conn: &PgConnection, person_block_form: &PersonBlockForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::person_block::dsl::*;
+    use crate::schema::person_block::dsl::*;
     insert_into(person_block)
       .values(person_block_form)
       .on_conflict((person_id, target_id))
@@ -39,7 +31,7 @@ impl Blockable for PersonBlock {
       .get_result::<Self>(conn)
   }
   fn unblock(conn: &PgConnection, person_block_form: &Self::Form) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::person_block::dsl::*;
+    use crate::schema::person_block::dsl::*;
     diesel::delete(
       person_block
         .filter(person_id.eq(person_block_form.person_id))
similarity index 77%
rename from crates/db_queries/src/source/person_mention.rs
rename to crates/db_schema/src/impls/person_mention.rs
index 1adcc3c989432efddb14e8286152e67a6ad7fb3f..df0e55edeb23481990a6eb522fb39baca7958cda 100644 (file)
@@ -1,17 +1,20 @@
-use crate::Crud;
+use crate::{
+  newtypes::{CommentId, PersonId, PersonMentionId},
+  source::person_mention::*,
+  traits::Crud,
+};
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{source::person_mention::*, CommentId, PersonId, PersonMentionId};
 
 impl Crud for PersonMention {
   type Form = PersonMentionForm;
   type IdType = PersonMentionId;
   fn read(conn: &PgConnection, person_mention_id: PersonMentionId) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::person_mention::dsl::*;
+    use crate::schema::person_mention::dsl::*;
     person_mention.find(person_mention_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, person_mention_form: &PersonMentionForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::person_mention::dsl::*;
+    use crate::schema::person_mention::dsl::*;
     // since the return here isnt utilized, we dont need to do an update
     // but get_result doesnt return the existing row here
     insert_into(person_mention)
@@ -27,47 +30,30 @@ impl Crud for PersonMention {
     person_mention_id: PersonMentionId,
     person_mention_form: &PersonMentionForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::person_mention::dsl::*;
+    use crate::schema::person_mention::dsl::*;
     diesel::update(person_mention.find(person_mention_id))
       .set(person_mention_form)
       .get_result::<Self>(conn)
   }
 }
 
-pub trait PersonMention_ {
-  fn update_read(
-    conn: &PgConnection,
-    person_mention_id: PersonMentionId,
-    new_read: bool,
-  ) -> Result<PersonMention, Error>;
-  fn mark_all_as_read(
-    conn: &PgConnection,
-    for_recipient_id: PersonId,
-  ) -> Result<Vec<PersonMention>, Error>;
-  fn read_by_comment_and_person(
-    conn: &PgConnection,
-    for_comment_id: CommentId,
-    for_recipient_id: PersonId,
-  ) -> Result<PersonMention, Error>;
-}
-
-impl PersonMention_ for PersonMention {
-  fn update_read(
+impl PersonMention {
+  pub fn update_read(
     conn: &PgConnection,
     person_mention_id: PersonMentionId,
     new_read: bool,
   ) -> Result<PersonMention, Error> {
-    use lemmy_db_schema::schema::person_mention::dsl::*;
+    use crate::schema::person_mention::dsl::*;
     diesel::update(person_mention.find(person_mention_id))
       .set(read.eq(new_read))
       .get_result::<Self>(conn)
   }
 
-  fn mark_all_as_read(
+  pub fn mark_all_as_read(
     conn: &PgConnection,
     for_recipient_id: PersonId,
   ) -> Result<Vec<PersonMention>, Error> {
-    use lemmy_db_schema::schema::person_mention::dsl::*;
+    use crate::schema::person_mention::dsl::*;
     diesel::update(
       person_mention
         .filter(recipient_id.eq(for_recipient_id))
@@ -76,12 +62,12 @@ impl PersonMention_ for PersonMention {
     .set(read.eq(true))
     .get_results::<Self>(conn)
   }
-  fn read_by_comment_and_person(
+  pub fn read_by_comment_and_person(
     conn: &PgConnection,
     for_comment_id: CommentId,
     for_recipient_id: PersonId,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::person_mention::dsl::*;
+    use crate::schema::person_mention::dsl::*;
     person_mention
       .filter(comment_id.eq(for_comment_id))
       .filter(recipient_id.eq(for_recipient_id))
@@ -91,13 +77,16 @@ impl PersonMention_ for PersonMention {
 
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, Crud};
-  use lemmy_db_schema::source::{
-    comment::*,
-    community::{Community, CommunityForm},
-    person::*,
-    person_mention::*,
-    post::*,
+  use crate::{
+    establish_unpooled_connection,
+    source::{
+      comment::*,
+      community::{Community, CommunityForm},
+      person::*,
+      person_mention::*,
+      post::*,
+    },
+    traits::Crud,
   };
   use serial_test::serial;
 
similarity index 75%
rename from crates/db_queries/src/source/post.rs
rename to crates/db_schema/src/impls/post.rs
index f9c34be8391c9e29605e010de826857c5ed444d3..2b71c663f4bb500c5e4a662e30b3b812521f4b15 100644 (file)
@@ -1,7 +1,6 @@
-use crate::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{
+use crate::{
   naive_now,
+  newtypes::{CommunityId, DbUrl, PersonId, PostId},
   source::post::{
     Post,
     PostForm,
@@ -12,75 +11,46 @@ use lemmy_db_schema::{
     PostSaved,
     PostSavedForm,
   },
-  CommunityId,
-  DbUrl,
-  PersonId,
-  PostId,
+  traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable},
 };
+use chrono::NaiveDateTime;
+use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
+use lemmy_apub_lib::traits::ApubObject;
+use lemmy_utils::LemmyError;
+use url::Url;
 
 impl Crud for Post {
   type Form = PostForm;
   type IdType = PostId;
   fn read(conn: &PgConnection, post_id: PostId) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     post.find(post_id).first::<Self>(conn)
   }
 
   fn delete(conn: &PgConnection, post_id: PostId) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     diesel::delete(post.find(post_id)).execute(conn)
   }
 
   fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     insert_into(post).values(new_post).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, post_id: PostId, new_post: &PostForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set(new_post)
       .get_result::<Self>(conn)
   }
 }
 
-pub trait Post_ {
-  //fn read(conn: &PgConnection, post_id: i32) -> Result<Post, Error>;
-  fn list_for_community(
-    conn: &PgConnection,
-    the_community_id: CommunityId,
-  ) -> Result<Vec<Post>, Error>;
-  fn update_ap_id(conn: &PgConnection, post_id: PostId, apub_id: DbUrl) -> Result<Post, Error>;
-  fn permadelete_for_creator(
-    conn: &PgConnection,
-    for_creator_id: PersonId,
-  ) -> Result<Vec<Post>, Error>;
-  fn update_deleted(conn: &PgConnection, post_id: PostId, new_deleted: bool)
-    -> Result<Post, Error>;
-  fn update_removed(conn: &PgConnection, post_id: PostId, new_removed: bool)
-    -> Result<Post, Error>;
-  fn update_removed_for_creator(
-    conn: &PgConnection,
-    for_creator_id: PersonId,
-    for_community_id: Option<CommunityId>,
-    new_removed: bool,
-  ) -> Result<Vec<Post>, Error>;
-  fn update_locked(conn: &PgConnection, post_id: PostId, new_locked: bool) -> Result<Post, Error>;
-  fn update_stickied(
-    conn: &PgConnection,
-    post_id: PostId,
-    new_stickied: bool,
-  ) -> Result<Post, Error>;
-  fn is_post_creator(person_id: PersonId, post_creator_id: PersonId) -> bool;
-  fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error>;
-}
-
-impl Post_ for Post {
-  fn list_for_community(
+impl Post {
+  pub fn list_for_community(
     conn: &PgConnection,
     the_community_id: CommunityId,
   ) -> Result<Vec<Self>, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     post
       .filter(community_id.eq(the_community_id))
       .then_order_by(published.desc())
@@ -89,19 +59,19 @@ impl Post_ for Post {
       .load::<Self>(conn)
   }
 
-  fn update_ap_id(conn: &PgConnection, post_id: PostId, apub_id: DbUrl) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+  pub fn update_ap_id(conn: &PgConnection, post_id: PostId, apub_id: DbUrl) -> Result<Self, Error> {
+    use crate::schema::post::dsl::*;
 
     diesel::update(post.find(post_id))
       .set(ap_id.eq(apub_id))
       .get_result::<Self>(conn)
   }
 
-  fn permadelete_for_creator(
+  pub fn permadelete_for_creator(
     conn: &PgConnection,
     for_creator_id: PersonId,
   ) -> Result<Vec<Self>, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
 
     let perma_deleted = "*Permananently Deleted*";
     let perma_deleted_url = "https://deleted.com";
@@ -117,35 +87,35 @@ impl Post_ for Post {
       .get_results::<Self>(conn)
   }
 
-  fn update_deleted(
+  pub fn update_deleted(
     conn: &PgConnection,
     post_id: PostId,
     new_deleted: bool,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set((deleted.eq(new_deleted), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn update_removed(
+  pub fn update_removed(
     conn: &PgConnection,
     post_id: PostId,
     new_removed: bool,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn update_removed_for_creator(
+  pub fn update_removed_for_creator(
     conn: &PgConnection,
     for_creator_id: PersonId,
     for_community_id: Option<CommunityId>,
     new_removed: bool,
   ) -> Result<Vec<Self>, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
 
     let mut update = diesel::update(post).into_boxed();
     update = update.filter(creator_id.eq(for_creator_id));
@@ -159,30 +129,34 @@ impl Post_ for Post {
       .get_results::<Self>(conn)
   }
 
-  fn update_locked(conn: &PgConnection, post_id: PostId, new_locked: bool) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+  pub fn update_locked(
+    conn: &PgConnection,
+    post_id: PostId,
+    new_locked: bool,
+  ) -> Result<Self, Error> {
+    use crate::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set(locked.eq(new_locked))
       .get_result::<Self>(conn)
   }
 
-  fn update_stickied(
+  pub fn update_stickied(
     conn: &PgConnection,
     post_id: PostId,
     new_stickied: bool,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+    use crate::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set(stickied.eq(new_stickied))
       .get_result::<Self>(conn)
   }
 
-  fn is_post_creator(person_id: PersonId, post_creator_id: PersonId) -> bool {
+  pub fn is_post_creator(person_id: PersonId, post_creator_id: PersonId) -> bool {
     person_id == post_creator_id
   }
 
-  fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
-    use lemmy_db_schema::schema::post::dsl::*;
+  pub fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
+    use crate::schema::post::dsl::*;
     insert_into(post)
       .values(post_form)
       .on_conflict(ap_id)
@@ -196,7 +170,7 @@ impl Likeable for PostLike {
   type Form = PostLikeForm;
   type IdType = PostId;
   fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post_like::dsl::*;
+    use crate::schema::post_like::dsl::*;
     insert_into(post_like)
       .values(post_like_form)
       .on_conflict((post_id, person_id))
@@ -205,7 +179,7 @@ impl Likeable for PostLike {
       .get_result::<Self>(conn)
   }
   fn remove(conn: &PgConnection, person_id: PersonId, post_id: PostId) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::post_like::dsl;
+    use crate::schema::post_like::dsl;
     diesel::delete(
       dsl::post_like
         .filter(dsl::post_id.eq(post_id))
@@ -218,7 +192,7 @@ impl Likeable for PostLike {
 impl Saveable for PostSaved {
   type Form = PostSavedForm;
   fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post_saved::dsl::*;
+    use crate::schema::post_saved::dsl::*;
     insert_into(post_saved)
       .values(post_saved_form)
       .on_conflict((post_id, person_id))
@@ -227,7 +201,7 @@ impl Saveable for PostSaved {
       .get_result::<Self>(conn)
   }
   fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::post_saved::dsl::*;
+    use crate::schema::post_saved::dsl::*;
     diesel::delete(
       post_saved
         .filter(post_id.eq(post_saved_form.post_id))
@@ -240,7 +214,7 @@ impl Saveable for PostSaved {
 impl Readable for PostRead {
   type Form = PostReadForm;
   fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post_read::dsl::*;
+    use crate::schema::post_read::dsl::*;
     insert_into(post_read)
       .values(post_read_form)
       .on_conflict((post_id, person_id))
@@ -250,7 +224,7 @@ impl Readable for PostRead {
   }
 
   fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::post_read::dsl::*;
+    use crate::schema::post_read::dsl::*;
     diesel::delete(
       post_read
         .filter(post_id.eq(post_read_form.post_id))
@@ -274,12 +248,38 @@ impl DeleteableOrRemoveable for Post {
   }
 }
 
+impl ApubObject for Post {
+  type DataType = PgConnection;
+
+  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+    None
+  }
+
+  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
+    use crate::schema::post::dsl::*;
+    let object_id: DbUrl = object_id.into();
+    Ok(post.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())
+  }
+
+  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
+    use crate::schema::post::dsl::*;
+    diesel::update(post.find(self.id))
+      .set((deleted.eq(true), updated.eq(naive_now())))
+      .get_result::<Self>(conn)?;
+    Ok(())
+  }
+}
+
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, source::post::*};
-  use lemmy_db_schema::source::{
-    community::{Community, CommunityForm},
-    person::*,
+  use crate::{
+    establish_unpooled_connection,
+    source::{
+      community::{Community, CommunityForm},
+      person::*,
+      post::*,
+    },
+    traits::{Crud, Likeable, Readable, Saveable},
   };
   use serial_test::serial;
 
similarity index 85%
rename from crates/db_queries/src/source/post_report.rs
rename to crates/db_schema/src/impls/post_report.rs
index e787fed4c385e6339c056a22ccf32f1520e67dc2..d049fbced7abf890a5b292ed266f90d4267b82e2 100644 (file)
@@ -1,6 +1,10 @@
-use crate::Reportable;
+use crate::{
+  naive_now,
+  newtypes::{PersonId, PostReportId},
+  source::post_report::*,
+  traits::Reportable,
+};
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{naive_now, source::post_report::*, PersonId, PostReportId};
 
 impl Reportable for PostReport {
   type Form = PostReportForm;
@@ -11,7 +15,7 @@ impl Reportable for PostReport {
   /// * `conn` - the postgres connection
   /// * `post_report_form` - the filled CommentReportForm to insert
   fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::post_report::dsl::*;
+    use crate::schema::post_report::dsl::*;
     insert_into(post_report)
       .values(post_report_form)
       .get_result::<Self>(conn)
@@ -27,7 +31,7 @@ impl Reportable for PostReport {
     report_id: Self::IdType,
     by_resolver_id: PersonId,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::post_report::dsl::*;
+    use crate::schema::post_report::dsl::*;
     update(post_report.find(report_id))
       .set((
         resolved.eq(true),
@@ -47,7 +51,7 @@ impl Reportable for PostReport {
     report_id: Self::IdType,
     by_resolver_id: PersonId,
   ) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::post_report::dsl::*;
+    use crate::schema::post_report::dsl::*;
     update(post_report.find(report_id))
       .set((
         resolved.eq(false),
similarity index 72%
rename from crates/db_queries/src/source/private_message.rs
rename to crates/db_schema/src/impls/private_message.rs
index 3aa279b2c0c84630141797829aa6ba7398b987cf..f252a0c031ccbb8342595722db0d6bb5fc44cc68 100644 (file)
@@ -1,17 +1,25 @@
-use crate::{Crud, DeleteableOrRemoveable};
+use crate::{
+  naive_now,
+  newtypes::{DbUrl, PersonId, PrivateMessageId},
+  source::private_message::*,
+  traits::{Crud, DeleteableOrRemoveable},
+};
+use chrono::NaiveDateTime;
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
+use lemmy_apub_lib::traits::ApubObject;
+use lemmy_utils::LemmyError;
+use url::Url;
 
 impl Crud for PrivateMessage {
   type Form = PrivateMessageForm;
   type IdType = PrivateMessageId;
   fn read(conn: &PgConnection, private_message_id: PrivateMessageId) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     private_message.find(private_message_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     insert_into(private_message)
       .values(private_message_form)
       .get_result::<Self>(conn)
@@ -22,95 +30,64 @@ impl Crud for PrivateMessage {
     private_message_id: PrivateMessageId,
     private_message_form: &PrivateMessageForm,
   ) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set(private_message_form)
       .get_result::<Self>(conn)
   }
 }
 
-pub trait PrivateMessage_ {
-  fn update_ap_id(
-    conn: &PgConnection,
-    private_message_id: PrivateMessageId,
-    apub_id: DbUrl,
-  ) -> Result<PrivateMessage, Error>;
-  fn update_content(
-    conn: &PgConnection,
-    private_message_id: PrivateMessageId,
-    new_content: &str,
-  ) -> Result<PrivateMessage, Error>;
-  fn update_deleted(
-    conn: &PgConnection,
-    private_message_id: PrivateMessageId,
-    new_deleted: bool,
-  ) -> Result<PrivateMessage, Error>;
-  fn update_read(
-    conn: &PgConnection,
-    private_message_id: PrivateMessageId,
-    new_read: bool,
-  ) -> Result<PrivateMessage, Error>;
-  fn mark_all_as_read(
-    conn: &PgConnection,
-    for_recipient_id: PersonId,
-  ) -> Result<Vec<PrivateMessage>, Error>;
-  fn upsert(
-    conn: &PgConnection,
-    private_message_form: &PrivateMessageForm,
-  ) -> Result<PrivateMessage, Error>;
-}
-
-impl PrivateMessage_ for PrivateMessage {
-  fn update_ap_id(
+impl PrivateMessage {
+  pub fn update_ap_id(
     conn: &PgConnection,
     private_message_id: PrivateMessageId,
     apub_id: DbUrl,
   ) -> Result<PrivateMessage, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
 
     diesel::update(private_message.find(private_message_id))
       .set(ap_id.eq(apub_id))
       .get_result::<Self>(conn)
   }
 
-  fn update_content(
+  pub fn update_content(
     conn: &PgConnection,
     private_message_id: PrivateMessageId,
     new_content: &str,
   ) -> Result<PrivateMessage, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set((content.eq(new_content), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn update_deleted(
+  pub fn update_deleted(
     conn: &PgConnection,
     private_message_id: PrivateMessageId,
     new_deleted: bool,
   ) -> Result<PrivateMessage, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set(deleted.eq(new_deleted))
       .get_result::<Self>(conn)
   }
 
-  fn update_read(
+  pub fn update_read(
     conn: &PgConnection,
     private_message_id: PrivateMessageId,
     new_read: bool,
   ) -> Result<PrivateMessage, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set(read.eq(new_read))
       .get_result::<Self>(conn)
   }
 
-  fn mark_all_as_read(
+  pub fn mark_all_as_read(
     conn: &PgConnection,
     for_recipient_id: PersonId,
   ) -> Result<Vec<PrivateMessage>, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     diesel::update(
       private_message
         .filter(recipient_id.eq(for_recipient_id))
@@ -120,11 +97,11 @@ impl PrivateMessage_ for PrivateMessage {
     .get_results::<Self>(conn)
   }
 
-  fn upsert(
+  pub fn upsert(
     conn: &PgConnection,
     private_message_form: &PrivateMessageForm,
   ) -> Result<PrivateMessage, Error> {
-    use lemmy_db_schema::schema::private_message::dsl::*;
+    use crate::schema::private_message::dsl::*;
     insert_into(private_message)
       .values(private_message_form)
       .on_conflict(ap_id)
@@ -141,10 +118,37 @@ impl DeleteableOrRemoveable for PrivateMessage {
   }
 }
 
+impl ApubObject for PrivateMessage {
+  type DataType = PgConnection;
+
+  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
+    None
+  }
+
+  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
+    use crate::schema::private_message::dsl::*;
+    let object_id: DbUrl = object_id.into();
+    Ok(
+      private_message
+        .filter(ap_id.eq(object_id))
+        .first::<Self>(conn)
+        .ok(),
+    )
+  }
+
+  fn delete(self, _conn: &PgConnection) -> Result<(), LemmyError> {
+    // do nothing, because pm can't be fetched over http
+    unimplemented!()
+  }
+}
+
 #[cfg(test)]
 mod tests {
-  use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud};
-  use lemmy_db_schema::source::{person::*, private_message::*};
+  use crate::{
+    establish_unpooled_connection,
+    source::{person::*, private_message::*},
+    traits::Crud,
+  };
   use serial_test::serial;
 
   #[test]
diff --git a/crates/db_schema/src/impls/secret.rs b/crates/db_schema/src/impls/secret.rs
new file mode 100644 (file)
index 0000000..3fb9b32
--- /dev/null
@@ -0,0 +1,15 @@
+use crate::source::secret::Secret;
+use diesel::{result::Error, *};
+
+impl Secret {
+  /// Initialize the Secrets from the DB.
+  /// Warning: You should only call this once.
+  pub fn init(conn: &PgConnection) -> Result<Secret, Error> {
+    read_secrets(conn)
+  }
+}
+
+fn read_secrets(conn: &PgConnection) -> Result<Secret, Error> {
+  use crate::schema::secret::dsl::*;
+  secret.first::<Secret>(conn)
+}
similarity index 55%
rename from crates/db_queries/src/source/site.rs
rename to crates/db_schema/src/impls/site.rs
index b2bad71384999d2fff7deff8c3ef87772ec8ab8d..af0e8153d08ec148277e23cf0feb4720cfa9c013 100644 (file)
@@ -1,47 +1,41 @@
-use crate::Crud;
+use crate::{naive_now, newtypes::PersonId, source::site::*, traits::Crud};
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{naive_now, source::site::*, PersonId};
 
 impl Crud for Site {
   type Form = SiteForm;
   type IdType = i32;
   fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::site::dsl::*;
+    use crate::schema::site::dsl::*;
     site.first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::site::dsl::*;
+    use crate::schema::site::dsl::*;
     insert_into(site).values(new_site).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::site::dsl::*;
+    use crate::schema::site::dsl::*;
     diesel::update(site.find(site_id))
       .set(new_site)
       .get_result::<Self>(conn)
   }
   fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
-    use lemmy_db_schema::schema::site::dsl::*;
+    use crate::schema::site::dsl::*;
     diesel::delete(site.find(site_id)).execute(conn)
   }
 }
 
-pub trait Site_ {
-  fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error>;
-  fn read_simple(conn: &PgConnection) -> Result<Site, Error>;
-}
-
-impl Site_ for Site {
-  fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error> {
-    use lemmy_db_schema::schema::site::dsl::*;
+impl Site {
+  pub fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error> {
+    use crate::schema::site::dsl::*;
     diesel::update(site.find(1))
       .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::site::dsl::*;
+  pub fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
+    use crate::schema::site::dsl::*;
     site.first::<Self>(conn)
   }
 }
index cc29848de319fc037c925089bd73ddc59a43a02b..f30f0bd80b92059edcd1fc051c8cae55644e0d3c 100644 (file)
 #[macro_use]
 extern crate diesel;
-
 #[macro_use]
 extern crate diesel_derive_newtype;
+#[macro_use]
+extern crate lazy_static;
+// this is used in tests
+#[allow(unused_imports)]
+#[macro_use]
+extern crate diesel_migrations;
+#[macro_use]
+extern crate strum_macros;
 
+pub mod aggregates;
+pub mod impls;
+pub mod newtypes;
+pub mod schema;
+pub mod source;
+pub mod traits;
+
+pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
+
+use crate::newtypes::DbUrl;
 use chrono::NaiveDateTime;
-use diesel::{
-  backend::Backend,
-  deserialize::FromSql,
-  serialize::{Output, ToSql},
-  sql_types::Text,
-};
+use diesel::{Connection, PgConnection};
+use lemmy_utils::ApiError;
+use regex::Regex;
 use serde::{Deserialize, Serialize};
-use std::{
-  fmt,
-  fmt::{Display, Formatter},
-  io::Write,
-};
+use std::{env, env::VarError};
 use url::Url;
 
-pub mod schema;
-pub mod source;
-
-#[derive(
-  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
-)]
-pub struct PostId(pub i32);
+pub fn get_database_url_from_env() -> Result<String, VarError> {
+  env::var("LEMMY_DATABASE_URL")
+}
 
-impl fmt::Display for PostId {
-  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-    write!(f, "{}", self.0)
-  }
+#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
+pub enum SortType {
+  Active,
+  Hot,
+  New,
+  TopDay,
+  TopWeek,
+  TopMonth,
+  TopYear,
+  TopAll,
+  MostComments,
+  NewComments,
 }
 
-#[derive(
-  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
-)]
-pub struct PersonId(pub i32);
+#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
+pub enum ListingType {
+  All,
+  Local,
+  Subscribed,
+  Community,
+}
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct CommentId(pub i32);
+#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
+pub enum SearchType {
+  All,
+  Comments,
+  Posts,
+  Communities,
+  Users,
+  Url,
+}
 
-impl fmt::Display for CommentId {
-  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-    write!(f, "{}", self.0)
-  }
+pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
+  opt.as_ref().map(|t| T::from_str(t).ok()).flatten()
 }
 
-#[derive(
-  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
-)]
-pub struct CommunityId(pub i32);
+pub fn fuzzy_search(q: &str) -> String {
+  let replaced = q.replace(" ", "%");
+  format!("%{}%", replaced)
+}
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct LocalUserId(pub i32);
+pub fn limit_and_offset(page: Option<i64>, limit: Option<i64>) -> (i64, i64) {
+  let page = page.unwrap_or(1);
+  let limit = limit.unwrap_or(10);
+  let offset = limit * (page - 1);
+  (limit, offset)
+}
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct PrivateMessageId(i32);
+pub fn is_email_regex(test: &str) -> bool {
+  EMAIL_REGEX.is_match(test)
+}
 
-impl fmt::Display for PrivateMessageId {
-  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-    write!(f, "{}", self.0)
+pub fn diesel_option_overwrite(opt: &Option<String>) -> Option<Option<String>> {
+  match opt {
+    // An empty string is an erase
+    Some(unwrapped) => {
+      if !unwrapped.eq("") {
+        Some(Some(unwrapped.to_owned()))
+      } else {
+        Some(None)
+      }
+    }
+    None => None,
   }
 }
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct PersonMentionId(i32);
-
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct PersonBlockId(i32);
+pub fn diesel_option_overwrite_to_url(
+  opt: &Option<String>,
+) -> Result<Option<Option<DbUrl>>, ApiError> {
+  match opt.as_ref().map(|s| s.as_str()) {
+    // An empty string is an erase
+    Some("") => Ok(Some(None)),
+    Some(str_url) => match Url::parse(str_url) {
+      Ok(url) => Ok(Some(Some(url.into()))),
+      Err(e) => Err(ApiError::err("invalid_url", e)),
+    },
+    None => Ok(None),
+  }
+}
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct CommunityBlockId(i32);
+embed_migrations!();
+
+pub fn establish_unpooled_connection() -> PgConnection {
+  let db_url = match get_database_url_from_env() {
+    Ok(url) => url,
+    Err(e) => panic!(
+      "Failed to read database URL from env var LEMMY_DATABASE_URL: {}",
+      e
+    ),
+  };
+  let conn =
+    PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
+  embedded_migrations::run(&conn).expect("load migrations");
+  conn
+}
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct CommentReportId(i32);
+pub fn naive_now() -> NaiveDateTime {
+  chrono::prelude::Utc::now().naive_utc()
+}
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
-pub struct PostReportId(i32);
+lazy_static! {
+  static ref EMAIL_REGEX: Regex =
+    Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
+      .expect("compile email regex");
+}
 
-#[repr(transparent)]
-#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
-#[sql_type = "Text"]
-pub struct DbUrl(Url);
+pub mod functions {
+  use diesel::sql_types::*;
 
-impl<DB: Backend> ToSql<Text, DB> for DbUrl
-where
-  String: ToSql<Text, DB>,
-{
-  fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
-    self.0.to_string().to_sql(out)
+  sql_function! {
+    fn hot_rank(score: BigInt, time: Timestamp) -> Integer;
   }
 }
 
-impl<DB: Backend> FromSql<Text, DB> for DbUrl
-where
-  String: FromSql<Text, DB>,
-{
-  fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
-    let str = String::from_sql(bytes)?;
-    Ok(DbUrl(Url::parse(&str)?))
-  }
-}
+#[cfg(test)]
+mod tests {
+  use super::{fuzzy_search, *};
+  use crate::is_email_regex;
 
-impl DbUrl {
-  // TODO: remove this method and just use into()
-  pub fn into_inner(self) -> Url {
-    self.0
+  #[test]
+  fn test_fuzzy_search() {
+    let test = "This is a fuzzy search";
+    assert_eq!(fuzzy_search(test), "%This%is%a%fuzzy%search%".to_string());
   }
-}
 
-impl Display for DbUrl {
-  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-    self.to_owned().0.fmt(f)
+  #[test]
+  fn test_email() {
+    assert!(is_email_regex("gush@gmail.com"));
+    assert!(!is_email_regex("nada_neutho"));
   }
-}
 
-impl From<DbUrl> for Url {
-  fn from(url: DbUrl) -> Self {
-    url.0
+  #[test]
+  fn test_diesel_option_overwrite() {
+    assert_eq!(diesel_option_overwrite(&None), None);
+    assert_eq!(diesel_option_overwrite(&Some("".to_string())), Some(None));
+    assert_eq!(
+      diesel_option_overwrite(&Some("test".to_string())),
+      Some(Some("test".to_string()))
+    );
   }
-}
 
-impl From<Url> for DbUrl {
-  fn from(url: Url) -> Self {
-    DbUrl(url)
+  #[test]
+  fn test_diesel_option_overwrite_to_url() {
+    assert!(matches!(diesel_option_overwrite_to_url(&None), Ok(None)));
+    assert!(matches!(
+      diesel_option_overwrite_to_url(&Some("".to_string())),
+      Ok(Some(None))
+    ));
+    assert!(matches!(
+      diesel_option_overwrite_to_url(&Some("invalid_url".to_string())),
+      Err(_)
+    ));
+    let example_url = "https://example.com";
+    assert!(matches!(
+      diesel_option_overwrite_to_url(&Some(example_url.to_string())),
+      Ok(Some(Some(url))) if url == Url::parse(example_url).unwrap().into()
+    ));
   }
 }
-
-// TODO: can probably move this back to lemmy_db_queries
-pub fn naive_now() -> NaiveDateTime {
-  chrono::prelude::Utc::now().naive_utc()
-}
diff --git a/crates/db_schema/src/newtypes.rs b/crates/db_schema/src/newtypes.rs
new file mode 100644 (file)
index 0000000..3042d35
--- /dev/null
@@ -0,0 +1,119 @@
+use diesel::{
+  backend::Backend,
+  deserialize::FromSql,
+  serialize::{Output, ToSql},
+  sql_types::Text,
+};
+use serde::{Deserialize, Serialize};
+use std::{
+  fmt,
+  fmt::{Display, Formatter},
+  io::Write,
+};
+use url::Url;
+
+#[derive(
+  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
+)]
+pub struct PostId(pub i32);
+
+impl fmt::Display for PostId {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+    write!(f, "{}", self.0)
+  }
+}
+
+#[derive(
+  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
+)]
+pub struct PersonId(pub i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct CommentId(pub i32);
+
+impl fmt::Display for CommentId {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+    write!(f, "{}", self.0)
+  }
+}
+
+#[derive(
+  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
+)]
+pub struct CommunityId(pub i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct LocalUserId(pub i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct PrivateMessageId(i32);
+
+impl fmt::Display for PrivateMessageId {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+    write!(f, "{}", self.0)
+  }
+}
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct PersonMentionId(i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct PersonBlockId(i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct CommunityBlockId(i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct CommentReportId(i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+pub struct PostReportId(i32);
+
+#[repr(transparent)]
+#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
+#[sql_type = "Text"]
+pub struct DbUrl(Url);
+
+impl<DB: Backend> ToSql<Text, DB> for DbUrl
+where
+  String: ToSql<Text, DB>,
+{
+  fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
+    self.0.to_string().to_sql(out)
+  }
+}
+
+impl<DB: Backend> FromSql<Text, DB> for DbUrl
+where
+  String: FromSql<Text, DB>,
+{
+  fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
+    let str = String::from_sql(bytes)?;
+    Ok(DbUrl(Url::parse(&str)?))
+  }
+}
+
+impl DbUrl {
+  // TODO: remove this method and just use into()
+  pub fn into_inner(self) -> Url {
+    self.0
+  }
+}
+
+impl Display for DbUrl {
+  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+    self.to_owned().0.fmt(f)
+  }
+}
+
+impl From<DbUrl> for Url {
+  fn from(url: DbUrl) -> Self {
+    url.0
+  }
+}
+
+impl From<Url> for DbUrl {
+  fn from(url: Url) -> Self {
+    DbUrl(url)
+  }
+}
index ced8f3be49c95a87e7119515db4cece71b5fbe64..c5ac833ed2aa109cb9a93d8091df998e1731b1f4 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{schema::activity, DbUrl};
+use crate::{newtypes::DbUrl, schema::activity};
 use serde_json::Value;
 use std::fmt::Debug;
 
index 54e8221f99307023872fc885a0e17c09b57fac59..46242fc738ba67b74d07fd339a24e236a0eb2bfe 100644 (file)
@@ -1,18 +1,9 @@
 use crate::{
-  naive_now,
+  newtypes::{CommentId, DbUrl, PersonId, PostId},
   schema::{comment, comment_alias_1, comment_like, comment_saved},
   source::post::Post,
-  CommentId,
-  DbUrl,
-  PersonId,
-  PostId,
 };
-use chrono::NaiveDateTime;
-use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::ApubObject;
-use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
-use url::Url;
 
 // WITH RECURSIVE MyTree AS (
 //     SELECT * FROM comment WHERE parent_id IS NULL
@@ -114,27 +105,3 @@ pub struct CommentSavedForm {
   pub comment_id: CommentId,
   pub person_id: PersonId,
 }
-
-impl ApubObject for Comment {
-  type DataType = PgConnection;
-
-  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
-    None
-  }
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
-    use crate::schema::comment::dsl::*;
-    let object_id: DbUrl = object_id.into();
-    Ok(comment.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())
-  }
-
-  // TODO: duplicate code from Comment::update_deleted(), we should really move all impls to
-  //       this crate so we can call that function from here
-  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
-    use crate::schema::comment::dsl::*;
-    diesel::update(comment.find(self.id))
-      .set((deleted.eq(true), updated.eq(naive_now())))
-      .get_result::<Self>(conn)?;
-    Ok(())
-  }
-}
index 57ca961de332f076cb0fbcabae27f16140e5f261..3c265ed09fc1d927538b1d6f4ccc0ab86ba2a166 100644 (file)
@@ -1,9 +1,7 @@
 use crate::{
+  newtypes::{CommentId, CommentReportId, PersonId},
   schema::comment_report,
   source::comment::Comment,
-  CommentId,
-  CommentReportId,
-  PersonId,
 };
 use serde::{Deserialize, Serialize};
 
index 365ddba7f6ca1745f66e2f01d002abeb249bab01..4c351b8860b0e295840e0065faf861fe006be1a5 100644 (file)
@@ -1,16 +1,8 @@
 use crate::{
-  naive_now,
+  newtypes::{CommunityId, DbUrl, PersonId},
   schema::{community, community_follower, community_moderator, community_person_ban},
-  CommunityId,
-  DbUrl,
-  PersonId,
 };
-use chrono::NaiveDateTime;
-use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::{ActorType, ApubObject};
-use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
-use url::Url;
 
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
 #[table_name = "community"]
@@ -130,56 +122,3 @@ pub struct CommunityFollowerForm {
   pub person_id: PersonId,
   pub pending: bool,
 }
-
-impl ApubObject for Community {
-  type DataType = PgConnection;
-
-  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
-    Some(self.last_refreshed_at)
-  }
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
-    use crate::schema::community::dsl::*;
-    let object_id: DbUrl = object_id.into();
-    Ok(
-      community
-        .filter(actor_id.eq(object_id))
-        .first::<Self>(conn)
-        .ok(),
-    )
-  }
-
-  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
-    use crate::schema::community::dsl::*;
-    diesel::update(community.find(self.id))
-      .set((deleted.eq(true), updated.eq(naive_now())))
-      .get_result::<Self>(conn)?;
-    Ok(())
-  }
-}
-
-impl ActorType for Community {
-  fn is_local(&self) -> bool {
-    self.local
-  }
-  fn actor_id(&self) -> Url {
-    self.actor_id.to_owned().into()
-  }
-  fn name(&self) -> String {
-    self.name.clone()
-  }
-  fn public_key(&self) -> Option<String> {
-    self.public_key.to_owned()
-  }
-  fn private_key(&self) -> Option<String> {
-    self.private_key.to_owned()
-  }
-
-  fn inbox_url(&self) -> Url {
-    self.inbox_url.clone().into()
-  }
-
-  fn shared_inbox_url(&self) -> Option<Url> {
-    self.shared_inbox_url.clone().map(|s| s.into_inner())
-  }
-}
index 35dfbd8a9bf0cb369a0b2b1111d9b20fc384043b..f5cc545e83988874caa3e8f5262320d74e5c7b15 100644 (file)
@@ -1,9 +1,7 @@
 use crate::{
+  newtypes::{CommunityBlockId, CommunityId, PersonId},
   schema::community_block,
   source::community::Community,
-  CommunityBlockId,
-  CommunityId,
-  PersonId,
 };
 use serde::{Deserialize, Serialize};
 
index d9fce8da911ac6f3514c35b7f83c8e00a65bbd1f..34dd26f764b5f0a19b06a5cf535a1510b3993012 100644 (file)
@@ -1,4 +1,7 @@
-use crate::{schema::local_user, LocalUserId, PersonId};
+use crate::{
+  newtypes::{LocalUserId, PersonId},
+  schema::local_user,
+};
 use serde::{Deserialize, Serialize};
 
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
index adde70351b21be36bf0c81a93c35265004c4949f..ee8bc693fe7ab860bedea13448050a5a15e9e882 100644 (file)
@@ -1,4 +1,5 @@
 use crate::{
+  newtypes::{CommentId, CommunityId, PersonId, PostId},
   schema::{
     mod_add,
     mod_add_community,
@@ -11,10 +12,6 @@ use crate::{
     mod_sticky_post,
     mod_transfer_community,
   },
-  CommentId,
-  CommunityId,
-  PersonId,
-  PostId,
 };
 use serde::{Deserialize, Serialize};
 
index 0af2d024d1964d0497a0dc172e0484d39da4a8c8..0d461049f7b1c78424a4f9669024db2c6e273978 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{schema::password_reset_request, LocalUserId};
+use crate::{newtypes::LocalUserId, schema::password_reset_request};
 
 #[derive(Queryable, Identifiable, PartialEq, Debug)]
 #[table_name = "password_reset_request"]
index f71f39dc91450116659ddbb194ad77126cee54bb..c9ffad7b3d4c45579d923988339b6f230d078c04 100644 (file)
@@ -1,15 +1,8 @@
 use crate::{
-  naive_now,
+  newtypes::{DbUrl, PersonId},
   schema::{person, person_alias_1, person_alias_2},
-  DbUrl,
-  PersonId,
 };
-use chrono::NaiveDateTime;
-use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::{ActorType, ApubObject};
-use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
-use url::Url;
 
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
 #[table_name = "person"]
@@ -176,59 +169,3 @@ pub struct PersonForm {
   pub admin: Option<bool>,
   pub bot_account: Option<bool>,
 }
-
-impl ApubObject for Person {
-  type DataType = PgConnection;
-
-  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
-    Some(self.last_refreshed_at)
-  }
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
-    use crate::schema::person::dsl::*;
-    let object_id: DbUrl = object_id.into();
-    Ok(
-      person
-        .filter(deleted.eq(false))
-        .filter(actor_id.eq(object_id))
-        .first::<Self>(conn)
-        .ok(),
-    )
-  }
-
-  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
-    use crate::schema::person::dsl::*;
-    diesel::update(person.find(self.id))
-      .set((deleted.eq(true), updated.eq(naive_now())))
-      .get_result::<Self>(conn)?;
-    Ok(())
-  }
-}
-
-impl ActorType for Person {
-  fn is_local(&self) -> bool {
-    self.local
-  }
-  fn actor_id(&self) -> Url {
-    self.actor_id.to_owned().into_inner()
-  }
-  fn name(&self) -> String {
-    self.name.clone()
-  }
-
-  fn public_key(&self) -> Option<String> {
-    self.public_key.to_owned()
-  }
-
-  fn private_key(&self) -> Option<String> {
-    self.private_key.to_owned()
-  }
-
-  fn inbox_url(&self) -> Url {
-    self.inbox_url.clone().into()
-  }
-
-  fn shared_inbox_url(&self) -> Option<Url> {
-    self.shared_inbox_url.clone().map(|s| s.into_inner())
-  }
-}
index c0ad15ca9379961e742968e4b5e8a482ffb56eb9..ff55872f195912f2909286268e4a58322e06ca83 100644 (file)
@@ -1,4 +1,7 @@
-use crate::{schema::person_block, PersonBlockId, PersonId};
+use crate::{
+  newtypes::{PersonBlockId, PersonId},
+  schema::person_block,
+};
 use serde::{Deserialize, Serialize};
 
 #[derive(
index d65a13b9d443772162af8ce35cc78aff93a16e48..795799c7e2a026102b6896548fd21418f3c2d189 100644 (file)
@@ -1,9 +1,7 @@
 use crate::{
+  newtypes::{CommentId, PersonId, PersonMentionId},
   schema::person_mention,
   source::comment::Comment,
-  CommentId,
-  PersonId,
-  PersonMentionId,
 };
 use serde::{Deserialize, Serialize};
 
index d28599c596cf9d7efbd8d0a607e5a8afdf94dbc6..cc9325361005c2df336dc5ed04b23101f55e0604 100644 (file)
@@ -1,18 +1,8 @@
 use crate::{
-  naive_now,
+  newtypes::{CommunityId, DbUrl, PersonId, PostId},
   schema::{post, post_like, post_read, post_saved},
-  CommunityId,
-  DbUrl,
-  PersonId,
-  PostId,
 };
-use chrono::NaiveDateTime;
-use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::ApubObject;
-use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
-use url::Url;
-
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
 #[table_name = "post"]
 pub struct Post {
@@ -112,25 +102,3 @@ pub struct PostReadForm {
   pub post_id: PostId,
   pub person_id: PersonId,
 }
-
-impl ApubObject for Post {
-  type DataType = PgConnection;
-
-  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
-    None
-  }
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
-    use crate::schema::post::dsl::*;
-    let object_id: DbUrl = object_id.into();
-    Ok(post.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())
-  }
-
-  fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
-    use crate::schema::post::dsl::*;
-    diesel::update(post.find(self.id))
-      .set((deleted.eq(true), updated.eq(naive_now())))
-      .get_result::<Self>(conn)?;
-    Ok(())
-  }
-}
index a146a4bef5116b1409f9984cef4bae0a620a04b6..6e711782b88c0c6ad093567328dbd4d50d97e96a 100644 (file)
@@ -1,4 +1,8 @@
-use crate::{schema::post_report, source::post::Post, DbUrl, PersonId, PostId, PostReportId};
+use crate::{
+  newtypes::{DbUrl, PersonId, PostId, PostReportId},
+  schema::post_report,
+  source::post::Post,
+};
 use serde::{Deserialize, Serialize};
 
 #[derive(
index 6247cb955be66eb3d44c3f69c60dabcfe16c674d..7facccaacd3ac5f247061e35b56b3d47eb0590bc 100644 (file)
@@ -1,10 +1,8 @@
-use crate::{schema::private_message, DbUrl, PersonId, PrivateMessageId};
-use chrono::NaiveDateTime;
-use diesel::{ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use lemmy_apub_lib::traits::ApubObject;
-use lemmy_utils::LemmyError;
+use crate::{
+  newtypes::{DbUrl, PersonId, PrivateMessageId},
+  schema::private_message,
+};
 use serde::{Deserialize, Serialize};
-use url::Url;
 
 #[derive(
   Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize,
@@ -36,27 +34,3 @@ pub struct PrivateMessageForm {
   pub ap_id: Option<DbUrl>,
   pub local: Option<bool>,
 }
-
-impl ApubObject for PrivateMessage {
-  type DataType = PgConnection;
-
-  fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
-    None
-  }
-
-  fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
-    use crate::schema::private_message::dsl::*;
-    let object_id: DbUrl = object_id.into();
-    Ok(
-      private_message
-        .filter(ap_id.eq(object_id))
-        .first::<Self>(conn)
-        .ok(),
-    )
-  }
-
-  fn delete(self, _conn: &PgConnection) -> Result<(), LemmyError> {
-    // do nothing, because pm can't be fetched over http
-    unimplemented!()
-  }
-}
index ec9dee84e4be5433b48e185434c42394c462d013..dd273f9dab9de991e78691abb761cd2e55d4e66f 100644 (file)
@@ -1,4 +1,7 @@
-use crate::{schema::site, DbUrl, PersonId};
+use crate::{
+  newtypes::{DbUrl, PersonId},
+  schema::site,
+};
 use serde::{Deserialize, Serialize};
 
 #[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize, Deserialize)]
diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs
new file mode 100644 (file)
index 0000000..aea36ed
--- /dev/null
@@ -0,0 +1,164 @@
+use crate::newtypes::{CommunityId, PersonId};
+use diesel::{result::Error, PgConnection};
+
+pub trait Crud {
+  type Form;
+  type IdType;
+  fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn read(conn: &PgConnection, id: Self::IdType) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn update(conn: &PgConnection, id: Self::IdType, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn delete(_conn: &PgConnection, _id: Self::IdType) -> Result<usize, Error>
+  where
+    Self: Sized,
+  {
+    unimplemented!()
+  }
+}
+
+pub trait Followable {
+  type Form;
+  fn follow(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn follow_accepted(
+    conn: &PgConnection,
+    community_id: CommunityId,
+    person_id: PersonId,
+  ) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn unfollow(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
+  where
+    Self: Sized;
+  fn has_local_followers(conn: &PgConnection, community_id: CommunityId) -> Result<bool, Error>;
+}
+
+pub trait Joinable {
+  type Form;
+  fn join(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn leave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait Likeable {
+  type Form;
+  type IdType;
+  fn like(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn remove(
+    conn: &PgConnection,
+    person_id: PersonId,
+    item_id: Self::IdType,
+  ) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait Bannable {
+  type Form;
+  fn ban(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn unban(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait Saveable {
+  type Form;
+  fn save(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn unsave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait Blockable {
+  type Form;
+  fn block(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn unblock(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait Readable {
+  type Form;
+  fn mark_as_read(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn mark_as_unread(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait Reportable {
+  type Form;
+  type IdType;
+  fn report(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
+  where
+    Self: Sized;
+  fn resolve(
+    conn: &PgConnection,
+    report_id: Self::IdType,
+    resolver_id: PersonId,
+  ) -> Result<usize, Error>
+  where
+    Self: Sized;
+  fn unresolve(
+    conn: &PgConnection,
+    report_id: Self::IdType,
+    resolver_id: PersonId,
+  ) -> Result<usize, Error>
+  where
+    Self: Sized;
+}
+
+pub trait DeleteableOrRemoveable {
+  fn blank_out_deleted_or_removed_info(self) -> Self;
+}
+
+pub trait MaybeOptional<T> {
+  fn get_optional(self) -> Option<T>;
+}
+
+impl<T> MaybeOptional<T> for T {
+  fn get_optional(self) -> Option<T> {
+    Some(self)
+  }
+}
+
+impl<T> MaybeOptional<T> for Option<T> {
+  fn get_optional(self) -> Option<T> {
+    self
+  }
+}
+
+pub trait ToSafe {
+  type SafeColumns;
+  fn safe_columns_tuple() -> Self::SafeColumns;
+}
+
+pub trait ToSafeSettings {
+  type SafeSettingsColumns;
+  fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
+}
+
+pub trait ViewToVec {
+  type DbTuple;
+  fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
+  where
+    Self: Sized;
+}
index 85afe569e9f2d2939ac000b8170d2d36b0c10b68..fbea198785c8b182ef71996f5c0988dd24d64e2d 100644 (file)
@@ -11,7 +11,6 @@ documentation = "https://join-lemmy.org/docs/en/index.html"
 doctest = false
 
 [dependencies]
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
 serde = { version = "1.0.130", features = ["derive"] }
index 7c2f99579de86c341dde989ba4dcf2355e7b9dd4..1469e42d01d01844fb59a9646386d62bea31c700 100644 (file)
@@ -1,12 +1,8 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::comment_aggregates::CommentAggregates,
   limit_and_offset,
-  MaybeOptional,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{CommentReportId, CommunityId, PersonId},
   schema::{
     comment,
     comment_aggregates,
@@ -27,9 +23,7 @@ use lemmy_db_schema::{
     person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2},
     post::Post,
   },
-  CommentReportId,
-  CommunityId,
-  PersonId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
@@ -309,14 +303,12 @@ impl ViewToVec for CommentReportView {
 #[cfg(test)]
 mod tests {
   use crate::comment_report_view::{CommentReportQueryBuilder, CommentReportView};
-  use lemmy_db_queries::{
+  use lemmy_db_schema::{
     aggregates::comment_aggregates::CommentAggregates,
     establish_unpooled_connection,
-    Crud,
-    Joinable,
-    Reportable,
+    source::{comment::*, comment_report::*, community::*, person::*, post::*},
+    traits::{Crud, Joinable, Reportable},
   };
-  use lemmy_db_schema::source::{comment::*, comment_report::*, community::*, person::*, post::*};
   use serial_test::serial;
 
   #[test]
index 2468c6536a7b46d02efa5f92a42be465c49ff38a..4fdd409705619d1d82c7ee618cbb59e8fc2cc10a 100644 (file)
@@ -1,16 +1,10 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::comment_aggregates::CommentAggregates,
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  ListingType,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{CommentId, CommunityId, DbUrl, PersonId, PostId},
   schema::{
     comment,
     comment_aggregates,
@@ -33,11 +27,9 @@ use lemmy_db_schema::{
     person_block::PersonBlock,
     post::Post,
   },
-  CommentId,
-  CommunityId,
-  DbUrl,
-  PersonId,
-  PostId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
+  ListingType,
+  SortType,
 };
 use serde::{Deserialize, Serialize};
 
@@ -526,19 +518,11 @@ impl ViewToVec for CommentView {
 #[cfg(test)]
 mod tests {
   use crate::comment_view::*;
-  use lemmy_db_queries::{
+  use lemmy_db_schema::{
     aggregates::comment_aggregates::CommentAggregates,
     establish_unpooled_connection,
-    Blockable,
-    Crud,
-    Likeable,
-  };
-  use lemmy_db_schema::source::{
-    comment::*,
-    community::*,
-    person::*,
-    person_block::PersonBlockForm,
-    post::*,
+    source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*},
+    traits::{Blockable, Crud, Likeable},
   };
   use serial_test::serial;
 
index 0e4d872ac60c82f49169e90bf1dec3a1ea428191..f697aba65792e1606ea675752796ddea6d42d62b 100644 (file)
@@ -1,13 +1,13 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{aggregates::person_aggregates::PersonAggregates, ToSafe, ToSafeSettings};
 use lemmy_db_schema::{
+  aggregates::person_aggregates::PersonAggregates,
+  newtypes::{LocalUserId, PersonId},
   schema::{local_user, person, person_aggregates},
   source::{
     local_user::{LocalUser, LocalUserSettings},
     person::{Person, PersonSafe},
   },
-  LocalUserId,
-  PersonId,
+  traits::{ToSafe, ToSafeSettings},
 };
 use serde::{Deserialize, Serialize};
 
index a8604ea9cdf3ce3b3f65b4df1917b74b13a4a240..f27ba50aad520c82f12d6b2878a515b4e40db4e2 100644 (file)
@@ -1,12 +1,8 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::post_aggregates::PostAggregates,
   limit_and_offset,
-  MaybeOptional,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId, PostReportId},
   schema::{
     community,
     community_moderator,
@@ -25,9 +21,7 @@ use lemmy_db_schema::{
     post::Post,
     post_report::PostReport,
   },
-  CommunityId,
-  PersonId,
-  PostReportId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
@@ -288,18 +282,16 @@ impl ViewToVec for PostReportView {
 #[cfg(test)]
 mod tests {
   use crate::post_report_view::{PostReportQueryBuilder, PostReportView};
-  use lemmy_db_queries::{
+  use lemmy_db_schema::{
     aggregates::post_aggregates::PostAggregates,
     establish_unpooled_connection,
-    Crud,
-    Joinable,
-    Reportable,
-  };
-  use lemmy_db_schema::source::{
-    community::*,
-    person::*,
-    post::*,
-    post_report::{PostReport, PostReportForm},
+    source::{
+      community::*,
+      person::*,
+      post::*,
+      post_report::{PostReport, PostReportForm},
+    },
+    traits::{Crud, Joinable, Reportable},
   };
   use serial_test::serial;
 
index f42a16599f0015528601951aff2fe775b0de957c..897a78e00f57b7b3c41ccb4ca80d4e56bf86ede8 100644 (file)
@@ -1,16 +1,10 @@
 use diesel::{pg::Pg, result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::post_aggregates::PostAggregates,
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  ListingType,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{CommunityId, DbUrl, PersonId, PostId},
   schema::{
     community,
     community_block,
@@ -30,10 +24,9 @@ use lemmy_db_schema::{
     person_block::PersonBlock,
     post::{Post, PostRead, PostSaved},
   },
-  CommunityId,
-  DbUrl,
-  PersonId,
-  PostId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
+  ListingType,
+  SortType,
 };
 use log::debug;
 use serde::{Deserialize, Serialize};
@@ -487,22 +480,20 @@ impl ViewToVec for PostView {
 #[cfg(test)]
 mod tests {
   use crate::post_view::{PostQueryBuilder, PostView};
-  use lemmy_db_queries::{
+  use lemmy_db_schema::{
     aggregates::post_aggregates::PostAggregates,
     establish_unpooled_connection,
-    Blockable,
-    Crud,
-    Likeable,
+    source::{
+      community::*,
+      community_block::{CommunityBlock, CommunityBlockForm},
+      person::*,
+      person_block::{PersonBlock, PersonBlockForm},
+      post::*,
+    },
+    traits::{Blockable, Crud, Likeable},
     ListingType,
     SortType,
   };
-  use lemmy_db_schema::source::{
-    community::*,
-    community_block::{CommunityBlock, CommunityBlockForm},
-    person::*,
-    person_block::{PersonBlock, PersonBlockForm},
-    post::*,
-  };
   use serial_test::serial;
 
   #[test]
index 7e322bbc71f5380c9b9d4a63a5c1a5b05c90da3a..940dbd366c0451ac74e8d043eb0e5e4e880ae846 100644 (file)
@@ -1,13 +1,13 @@
 use diesel::{pg::Pg, result::Error, *};
-use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{PersonId, PrivateMessageId},
   schema::{person, person_alias_1, private_message},
   source::{
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
     private_message::PrivateMessage,
   },
-  PersonId,
-  PrivateMessageId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
 };
 use log::debug;
 use serde::{Deserialize, Serialize};
index d0c2ee82df9c506e469759304282d1d1102f07b6..3c94975aa2034e170ebec22a43a7f2db83955250 100644 (file)
@@ -1,11 +1,12 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{aggregates::site_aggregates::SiteAggregates, ToSafe};
 use lemmy_db_schema::{
+  aggregates::site_aggregates::SiteAggregates,
   schema::{person, site, site_aggregates},
   source::{
     person::{Person, PersonSafe},
     site::Site,
   },
+  traits::ToSafe,
 };
 use serde::{Deserialize, Serialize};
 
index fa21bf87b8867f08b909ab967b4014a19522d403..ced1e8a2891ce556910c3fc79966bd940686d230 100644 (file)
@@ -11,7 +11,6 @@ documentation = "https://join-lemmy.org/docs/en/index.html"
 doctest = false
 
 [dependencies]
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
 serde = { version = "1.0.130", features = ["derive"] }
index 3046b0c2dc26b1a3fddfaf7b48965b0ab6d2224c..8f0cfca76342b5f5b5b0c88003ea95bb22b7c4fd 100644 (file)
@@ -1,12 +1,12 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  newtypes::PersonId,
   schema::{community, community_block, person},
   source::{
     community::{Community, CommunitySafe},
     person::{Person, PersonSafe},
   },
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index d3b11e4d265d6b949a74eaa7dfaa5cb7bc4325ec..379d70958a176d0198c5a24b95d83e3468f76156 100644 (file)
@@ -1,13 +1,12 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId},
   schema::{community, community_follower, person},
   source::{
     community::{Community, CommunitySafe},
     person::{Person, PersonSafe},
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 071fc107524df8dc1e109d9358e9d03885f4742e..1e48ad0ab92a505713170797ab064e68834087e4 100644 (file)
@@ -1,13 +1,12 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId},
   schema::{community, community_moderator, person},
   source::{
     community::{Community, CommunitySafe},
     person::{Person, PersonSafe},
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index b085492116ca7acf4c0686674b5705872f4055a6..bffbacb127beade59693fc22a8678cd72f019d44 100644 (file)
@@ -1,13 +1,12 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::ToSafe;
 use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId},
   schema::{community, community_person_ban, person},
   source::{
     community::{Community, CommunitySafe},
     person::{Person, PersonSafe},
   },
-  CommunityId,
-  PersonId,
+  traits::ToSafe,
 };
 use serde::{Deserialize, Serialize};
 
index 8ce3b7e6f111c6c2de7720353f3aaa8b934cc38a..48270c25c2de3a28d2a4bac081eebbd69fd4d80a 100644 (file)
@@ -1,24 +1,19 @@
 use crate::{community_moderator_view::CommunityModeratorView, person_view::PersonViewSafe};
 use diesel::{result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::community_aggregates::CommunityAggregates,
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  ListingType,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId},
   schema::{community, community_aggregates, community_block, community_follower},
   source::{
     community::{Community, CommunityFollower, CommunitySafe},
     community_block::CommunityBlock,
   },
-  CommunityId,
-  PersonId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
+  ListingType,
+  SortType,
 };
 use serde::{Deserialize, Serialize};
 
index d4a52860389e50abdb3d8378c143a71017578d53..2ca2077cbfd72f61ac706ddc411b08429d142119 100644 (file)
@@ -1,9 +1,9 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  newtypes::PersonId,
   schema::{person, person_alias_1, person_block},
   source::person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 1de01491f3f5418c2626b00a0f5b629de4bb41a2..5e6e3df3f2fff7dfdba01199e963fd9119b0c818 100644 (file)
@@ -1,14 +1,9 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::comment_aggregates::CommentAggregates,
   functions::hot_rank,
   limit_and_offset,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{PersonId, PersonMentionId},
   schema::{
     comment,
     comment_aggregates,
@@ -31,8 +26,8 @@ use lemmy_db_schema::{
     person_mention::PersonMention,
     post::Post,
   },
-  PersonId,
-  PersonMentionId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
+  SortType,
 };
 use serde::{Deserialize, Serialize};
 
index 496ac672f9db3aee8ff7523595e5a5a68140c498..b6585196b923e707b11602e03f306fc970e8928b 100644 (file)
@@ -1,17 +1,13 @@
 use diesel::{dsl::*, result::Error, *};
-use lemmy_db_queries::{
+use lemmy_db_schema::{
   aggregates::person_aggregates::PersonAggregates,
   fuzzy_search,
   limit_and_offset,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::PersonId,
   schema::{person, person_aggregates},
   source::person::{Person, PersonSafe},
-  PersonId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
+  SortType,
 };
 use serde::{Deserialize, Serialize};
 
index 3511d07d3fcc9f24397251fd1f3297824627d225..3a0b707cff957215e3dab2248dbab4dff8c8b5c6 100644 (file)
@@ -11,7 +11,6 @@ documentation = "https://join-lemmy.org/docs/en/index.html"
 doctest = false
 
 [dependencies]
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
 serde = { version = "1.0.130", features = ["derive"] }
index f5fe8af115d16dd5dcb0e8daaa80465ab89698a0..b0d72d21a0eff4a305443742cfbb423fd8d70579 100644 (file)
@@ -1,14 +1,14 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{community, mod_add_community, person, person_alias_1},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModAddCommunity,
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 0ac915539a42c566097bf3faf61fd59def2673a8..bd4e388b3c8bf3151e2672674e7bd297f225501e 100644 (file)
@@ -1,12 +1,13 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::PersonId,
   schema::{mod_add, person, person_alias_1},
   source::{
     moderator::ModAdd,
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index d67f82dfe7b1ce88ee65788db7fb568338733646..a5a37cce1c9e9861feedfa69abaf45e2738ed912 100644 (file)
@@ -1,14 +1,14 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{community, mod_ban_from_community, person, person_alias_1},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModBanFromCommunity,
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 79a199cb0d1bfe6b22a71f37d4db14ee79154c59..fabb56ca986dc1adba993f704d090c97c73532aa 100644 (file)
@@ -1,12 +1,13 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::PersonId,
   schema::{mod_ban, person, person_alias_1},
   source::{
     moderator::ModBan,
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 8774bfbd4bdc95f6f05acd735fe72955c0eac62a..5ec355791342c6042216944c2387cf8e2418dfce 100644 (file)
@@ -1,6 +1,7 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{community, mod_lock_post, person, post},
   source::{
     community::{Community, CommunitySafe},
@@ -8,8 +9,7 @@ use lemmy_db_schema::{
     person::{Person, PersonSafe},
     post::Post,
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 9cf9862e15f0e8fc5f86feb573be6c41eb032e7b..abb88020a56a841c9a83a198274614ea207fb1de 100644 (file)
@@ -1,6 +1,7 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{comment, community, mod_remove_comment, person, person_alias_1, post},
   source::{
     comment::Comment,
@@ -9,8 +10,7 @@ use lemmy_db_schema::{
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
     post::Post,
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 7196aec6b56f4423b53c3e113d4c1d82b8ef92e2..6634b2ff8bd84438207fdb55ee27c63f7f4f5441 100644 (file)
@@ -1,13 +1,14 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::PersonId,
   schema::{community, mod_remove_community, person},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModRemoveCommunity,
     person::{Person, PersonSafe},
   },
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index d83f95b4605a2f3d3f743a560ff57601b759158b..c92191610249f4af4628c86ade82f0033df912ed 100644 (file)
@@ -1,6 +1,7 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{community, mod_remove_post, person, post},
   source::{
     community::{Community, CommunitySafe},
@@ -8,8 +9,7 @@ use lemmy_db_schema::{
     person::{Person, PersonSafe},
     post::Post,
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index f1dfcb144548412b73c4e567dc9463052087bb48..55593e4fc8de4b90b6558dfee2b281e82a8163d3 100644 (file)
@@ -1,6 +1,7 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{community, mod_sticky_post, person, post},
   source::{
     community::{Community, CommunitySafe},
@@ -8,8 +9,7 @@ use lemmy_db_schema::{
     person::{Person, PersonSafe},
     post::Post,
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index 9fcc481be1ebe7bddf63e0c3b3789c193ee607d0..2fbacbb831e3aee5428e224513bfacee44efb296 100644 (file)
@@ -1,14 +1,14 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
+  limit_and_offset,
+  newtypes::{CommunityId, PersonId},
   schema::{community, mod_transfer_community, person, person_alias_1},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModTransferCommunity,
     person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
-  CommunityId,
-  PersonId,
+  traits::{ToSafe, ViewToVec},
 };
 use serde::{Deserialize, Serialize};
 
index dfa8c9482e423dae5f1ebe1a306f378be6007756..65dcb8cda650c02114a5ee1492c91b1606a0c45c 100644 (file)
@@ -13,7 +13,6 @@ doctest = false
 [dependencies]
 lemmy_utils = { version = "=0.13.0", path = "../utils" }
 lemmy_websocket = { version = "=0.13.0", path = "../websocket" }
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
 lemmy_db_views_actor = { version = "=0.13.0", path = "../db_views_actor" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
index a02b5fe3309dfb4dab46b2c40f039641a1ead6aa..1a85a10ac693806fc0cdf5ff155bff3449644ea6 100644 (file)
@@ -3,15 +3,12 @@ use anyhow::anyhow;
 use chrono::{DateTime, NaiveDateTime, Utc};
 use diesel::PgConnection;
 use lemmy_api_common::blocking;
-use lemmy_db_queries::{
-  source::{community::Community_, person::Person_},
-  Crud,
-  ListingType,
-  SortType,
-};
 use lemmy_db_schema::{
+  newtypes::LocalUserId,
   source::{community::Community, local_user::LocalUser, person::Person},
-  LocalUserId,
+  traits::Crud,
+  ListingType,
+  SortType,
 };
 use lemmy_db_views::{
   comment_view::{CommentQueryBuilder, CommentView},
index 798636da5bcb30e812e721064f800eb4451c27c6..ef0afd9903c56418d939b3801c695ab6f1d3d844 100644 (file)
@@ -2,7 +2,6 @@ use actix_web::{error::ErrorBadRequest, web::Query, *};
 use anyhow::anyhow;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::webfinger::{WebfingerLink, WebfingerResponse};
-use lemmy_db_queries::source::{community::Community_, person::Person_};
 use lemmy_db_schema::source::{community::Community, person::Person};
 use lemmy_utils::{settings::structs::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
index 6678b91f5d99776ae98ec29393d5ad96abcf19d9..40dd91664e761a699e8978200d8318661a86f6bf 100644 (file)
@@ -27,7 +27,7 @@ impl Settings {
   /// Reads config from configuration file.
   ///
   /// Note: The env var `LEMMY_DATABASE_URL` is parsed in
-  /// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()`
+  /// `lemmy_db_schema/src/lib.rs::get_database_url_from_env()`
   /// Warning: Only call this once.
   pub fn init() -> Result<Self, LemmyError> {
     // Read the config file
index cab4da4392349fcc599d68171ffb8924d4f49940..c7d5f3a6004211414ef858b859646956f4c0ba20 100644 (file)
@@ -15,7 +15,6 @@ doctest = false
 [dependencies]
 lemmy_utils = { version = "=0.13.0", path = "../utils" }
 lemmy_api_common = { version = "=0.13.0", path = "../api_common" }
-lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
 lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
 lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
 lemmy_db_views_actor = { version = "=0.13.0", path = "../db_views_actor" }
index db09ac95ee7eb64c5e791e7e2a4b8bbce19a2e6b..3e17b6262cd384507ba0c586cd6990e606ebe028 100644 (file)
@@ -14,7 +14,10 @@ use diesel::{
   PgConnection,
 };
 use lemmy_api_common::{comment::*, post::*};
-use lemmy_db_schema::{source::secret::Secret, CommunityId, LocalUserId, PostId};
+use lemmy_db_schema::{
+  newtypes::{CommunityId, LocalUserId, PostId},
+  source::secret::Secret,
+};
 use lemmy_utils::{
   location_info,
   rate_limit::RateLimit,
index e9f48874124155294d759335fa3ba40ce8431f5d..fbf9d25a3409ba6ece8cf17c72f37d3f5de2458b 100644 (file)
@@ -4,8 +4,7 @@ extern crate strum_macros;
 use crate::chat_server::ChatServer;
 use actix::Addr;
 use background_jobs::QueueHandle;
-use lemmy_db_queries::DbPool;
-use lemmy_db_schema::source::secret::Secret;
+use lemmy_db_schema::{source::secret::Secret, DbPool};
 use lemmy_utils::{settings::structs::Settings, LemmyError};
 use reqwest::Client;
 use serde::Serialize;
index 3c16ec2730f4169e612144adf463352d664b5c1c..4192b540220ec271f19d387037585502be077b6d 100644 (file)
@@ -1,7 +1,7 @@
 use crate::UserOperation;
 use actix::{prelude::*, Recipient};
 use lemmy_api_common::{comment::CommentResponse, post::PostResponse};
-use lemmy_db_schema::{CommunityId, LocalUserId, PostId};
+use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
 use lemmy_utils::{ConnectionId, IpAddr};
 use serde::{Deserialize, Serialize};
 
index a49759d639c2feda27ce2c31dc1df51daf77d9b5..5982e24cea50308249b94271051219159ef8f9ba 100644 (file)
@@ -10,8 +10,10 @@ use lemmy_api_common::{
   person::PrivateMessageResponse,
   post::PostResponse,
 };
-use lemmy_db_queries::DeleteableOrRemoveable;
-use lemmy_db_schema::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId};
+use lemmy_db_schema::{
+  newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
+  traits::DeleteableOrRemoveable,
+};
 use lemmy_db_views::{
   comment_view::CommentView,
   local_user_view::LocalUserView,
index 2474c74d61afef3fbe6655e1d717c95862d5e167..e1ea333adf963baeec34726565a77b312bb03735 100644 (file)
@@ -18,7 +18,7 @@ services:
       - "8536:8536"
     restart: always
     environment:
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     volumes:
       - ../lemmy.hjson:/config/config.hjson
     depends_on: 
index 55b3877cc12a8f1a354447713eae2f990f7c4cda..3a8447c1a046bfbd255ffa50349a4f201f3aefca 100644 (file)
@@ -42,7 +42,7 @@ services:
     environment:
       - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_alpha
     ports: 
@@ -71,7 +71,7 @@ services:
     environment:
       - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_beta
     ports: 
@@ -100,7 +100,7 @@ services:
     environment:
       - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_gamma
     ports: 
@@ -130,7 +130,7 @@ services:
     environment:
       - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_delta
     ports: 
@@ -160,7 +160,7 @@ services:
     environment:
       - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_epsilon
     ports: 
index a9d7e613fc4234b4910a6fee75591592dc3ac22d..2b39ab18a69c59580c6b08d428ec0078dd2c048b 100644 (file)
@@ -17,7 +17,7 @@ services:
       - "127.0.0.1:8536:8536"
     restart: always
     environment:
-      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
+      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
     volumes:
       - ./lemmy.hjson:/config/config.hjson
     depends_on:
index 1f9381986e954fd6486665d3dd8ea7ff663c5236..8910733a515f1604bf1e65fd1487e99d4beec393 100644 (file)
@@ -10,10 +10,6 @@ use lemmy_apub::{
   generate_shared_inbox_url,
   EndpointType,
 };
-use lemmy_db_queries::{
-  source::{comment::Comment_, post::Post_, private_message::PrivateMessage_},
-  Crud,
-};
 use lemmy_db_schema::{
   naive_now,
   source::{
@@ -23,6 +19,7 @@ use lemmy_db_schema::{
     post::Post,
     private_message::PrivateMessage,
   },
+  traits::Crud,
 };
 use lemmy_utils::{apub::generate_actor_keypair, LemmyError};
 use log::info;
index 483b174153e8a9c0e81011dd94c933145f34d845..c078e7860a0cc3ac7a9d3e8f8a7a66a807c8582d 100644 (file)
@@ -12,8 +12,7 @@ use lemmy_api::match_websocket_operation;
 use lemmy_api_common::blocking;
 use lemmy_api_crud::match_websocket_operation_crud;
 use lemmy_apub_lib::activity_queue::create_activity_queue;
-use lemmy_db_queries::{get_database_url_from_env, source::secret::Secret_};
-use lemmy_db_schema::source::secret::Secret;
+use lemmy_db_schema::{get_database_url_from_env, source::secret::Secret};
 use lemmy_routes::{feeds, images, nodeinfo, webfinger};
 use lemmy_server::{api_routes, code_migrations::run_advanced_migrations, scheduled_tasks};
 use lemmy_utils::{
index 5c406ff6d2913017285dae8ea25a878ab1f2112c..396c7b675f23b50ee52b9f4067933a916cf4c845 100644 (file)
@@ -2,8 +2,7 @@
 use clokwerk::{Scheduler, TimeUnits};
 // Import week days and WeekDay
 use diesel::{sql_query, PgConnection, RunQueryDsl};
-use lemmy_db_queries::{source::activity::Activity_, DbPool};
-use lemmy_db_schema::source::activity::Activity;
+use lemmy_db_schema::{source::activity::Activity, DbPool};
 use log::info;
 use std::{thread, time::Duration};