"lazy_static",
"lemmy_api_common",
"lemmy_apub",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"actix-web",
"chrono",
"diesel",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"lemmy_api_common",
"lemmy_apub",
"lemmy_apub_lib",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"itertools",
"lemmy_api_common",
"lemmy_apub_lib",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
]
[[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",
"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",
version = "0.13.0"
dependencies = [
"diesel",
- "lemmy_db_queries",
"lemmy_db_schema",
"serde",
]
version = "0.13.0"
dependencies = [
"diesel",
- "lemmy_db_queries",
"lemmy_db_schema",
"serde",
]
"lazy_static",
"lemmy_api_common",
"lemmy_apub_lib",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"lemmy_api_crud",
"lemmy_apub",
"lemmy_apub_lib",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"chrono",
"diesel",
"lemmy_api_common",
- "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"crates/apub_lib_derive",
"crates/apub",
"crates/utils",
- "crates/db_queries",
"crates/db_schema",
"crates/db_views",
"crates/db_views_actor",
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" }
- "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:
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"
[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" }
},
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};
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,
},
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::{
#[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};
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,
private_message::PrivateMessage,
site::*,
},
+ traits::{Blockable, Crud},
+ SortType,
};
use lemmy_db_views::{
comment_report_view::CommentReportView,
},
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};
},
};
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,
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};
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},
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 {
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" }
-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};
-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,
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,
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::{
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());
}
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 {
-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,
-use lemmy_db_schema::{CommunityId, PersonId};
+use lemmy_db_schema::newtypes::{CommunityId, PersonId};
use lemmy_db_views::{
comment_view::CommentView,
local_user_view::LocalUserSettingsView,
-use lemmy_db_schema::{CommunityId, PostId};
+use lemmy_db_schema::newtypes::{CommunityId, PostId};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
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" }
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},
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};
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;
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},
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::{
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};
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},
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};
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},
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};
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},
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},
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};
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};
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;
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};
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},
) -> 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());
};
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};
// 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);
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::{
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());
}
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;
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,
[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" }
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};
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},
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;
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;
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;
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;
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};
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::{
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::{
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::{
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;
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;
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;
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};
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};
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};
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};
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;
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::{
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;
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;
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};
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;
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;
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;
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,
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};
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;
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;
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};
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,
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::{
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;
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},
values::{MediaTypeHtml, MediaTypeMarkdown},
verify::verify_domains_match,
};
-use lemmy_db_queries::{source::post::Post_, Crud, DbPool};
use lemmy_db_schema::{
self,
source::{
person::Person,
post::{Post, PostForm},
},
+ traits::Crud,
+ DbPool,
};
use lemmy_utils::{
request::fetch_site_data,
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;
+++ /dev/null
-[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"
+++ /dev/null
-#[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()
- ));
- }
-}
+++ /dev/null
-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)
-}
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
+use crate::{newtypes::CommentId, schema::comment_aggregates};
use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::comment_aggregates, CommentId};
use serde::{Deserialize, Serialize};
#[derive(
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;
+use crate::{newtypes::CommunityId, schema::community_aggregates};
use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::community_aggregates, CommunityId};
use serde::{Deserialize, Serialize};
#[derive(
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;
+use crate::{newtypes::PersonId, schema::person_aggregates};
use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::person_aggregates, PersonId};
use serde::{Deserialize, Serialize};
#[derive(
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;
+use crate::{newtypes::PostId, schema::post_aggregates};
use diesel::{result::Error, *};
-use lemmy_db_schema::{schema::post_aggregates, PostId};
use serde::{Deserialize, Serialize};
#[derive(
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;
+use crate::schema::site_aggregates;
use diesel::{result::Error, *};
-use lemmy_db_schema::schema::site_aggregates;
use serde::{Deserialize, Serialize};
#[derive(
#[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;
-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::{
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)
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,
}
}
- 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(
#[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;
-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,
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*"),
.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)
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)
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)
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))
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))
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))
.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))
}
}
+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;
-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;
/// * `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)
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),
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),
-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,
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,
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)
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)
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)
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))
}
}
-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)
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)
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))
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))
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_))
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))
// 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_)),
))
}
}
+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]
-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))
.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))
-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,
}
}
-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");
Self::create(conn, &edited_user)
}
- fn update_password(
+ pub fn update_password(
conn: &PgConnection,
local_user_id: LocalUserId,
new_password: &str,
-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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
#[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;
-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 {
}
}
-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,
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());
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;
-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,
}
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,
}
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,
}
}
-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))
.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)))
.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)
}
}
+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() {
-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))
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))
.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))
-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)
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))
.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))
#[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;
-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,
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())
.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";
.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));
.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)
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))
.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))
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))
.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))
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))
}
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))
}
}
+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;
-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;
/// * `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)
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),
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),
-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)
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))
.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)
}
}
+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]
--- /dev/null
+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)
+}
-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)
}
}
#[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()
-}
--- /dev/null
+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)
+ }
+}
-use crate::{schema::activity, DbUrl};
+use crate::{newtypes::DbUrl, schema::activity};
use serde_json::Value;
use std::fmt::Debug;
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
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(())
- }
-}
use crate::{
+ newtypes::{CommentId, CommentReportId, PersonId},
schema::comment_report,
source::comment::Comment,
- CommentId,
- CommentReportId,
- PersonId,
};
use serde::{Deserialize, Serialize};
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"]
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())
- }
-}
use crate::{
+ newtypes::{CommunityBlockId, CommunityId, PersonId},
schema::community_block,
source::community::Community,
- CommunityBlockId,
- CommunityId,
- PersonId,
};
use serde::{Deserialize, Serialize};
-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)]
use crate::{
+ newtypes::{CommentId, CommunityId, PersonId, PostId},
schema::{
mod_add,
mod_add_community,
mod_sticky_post,
mod_transfer_community,
},
- CommentId,
- CommunityId,
- PersonId,
- PostId,
};
use serde::{Deserialize, Serialize};
-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"]
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"]
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())
- }
-}
-use crate::{schema::person_block, PersonBlockId, PersonId};
+use crate::{
+ newtypes::{PersonBlockId, PersonId},
+ schema::person_block,
+};
use serde::{Deserialize, Serialize};
#[derive(
use crate::{
+ newtypes::{CommentId, PersonId, PersonMentionId},
schema::person_mention,
source::comment::Comment,
- CommentId,
- PersonId,
- PersonMentionId,
};
use serde::{Deserialize, Serialize};
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 {
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(())
- }
-}
-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(
-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,
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!()
- }
-}
-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)]
--- /dev/null
+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;
+}
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"] }
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,
person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2},
post::Post,
},
- CommentReportId,
- CommunityId,
- PersonId,
+ traits::{MaybeOptional, ToSafe, ViewToVec},
};
use serde::{Deserialize, Serialize};
#[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]
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,
person_block::PersonBlock,
post::Post,
},
- CommentId,
- CommunityId,
- DbUrl,
- PersonId,
- PostId,
+ traits::{MaybeOptional, ToSafe, ViewToVec},
+ ListingType,
+ SortType,
};
use serde::{Deserialize, Serialize};
#[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;
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};
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,
post::Post,
post_report::PostReport,
},
- CommunityId,
- PersonId,
- PostReportId,
+ traits::{MaybeOptional, ToSafe, ViewToVec},
};
use serde::{Deserialize, Serialize};
#[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;
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,
person_block::PersonBlock,
post::{Post, PostRead, PostSaved},
},
- CommunityId,
- DbUrl,
- PersonId,
- PostId,
+ traits::{MaybeOptional, ToSafe, ViewToVec},
+ ListingType,
+ SortType,
};
use log::debug;
use serde::{Deserialize, Serialize};
#[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]
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};
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};
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"] }
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};
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};
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};
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};
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};
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};
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,
person_mention::PersonMention,
post::Post,
},
- PersonId,
- PersonMentionId,
+ traits::{MaybeOptional, ToSafe, ViewToVec},
+ SortType,
};
use serde::{Deserialize, Serialize};
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};
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"] }
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};
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};
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};
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};
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},
person::{Person, PersonSafe},
post::Post,
},
- CommunityId,
- PersonId,
+ traits::{ToSafe, ViewToVec},
};
use serde::{Deserialize, Serialize};
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,
person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
post::Post,
},
- CommunityId,
- PersonId,
+ traits::{ToSafe, ViewToVec},
};
use serde::{Deserialize, Serialize};
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};
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},
person::{Person, PersonSafe},
post::Post,
},
- CommunityId,
- PersonId,
+ traits::{ToSafe, ViewToVec},
};
use serde::{Deserialize, Serialize};
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},
person::{Person, PersonSafe},
post::Post,
},
- CommunityId,
- PersonId,
+ traits::{ToSafe, ViewToVec},
};
use serde::{Deserialize, Serialize};
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};
[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" }
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},
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;
/// 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
[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" }
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,
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;
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};
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,
- "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:
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:
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:
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:
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:
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:
- "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:
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::{
post::Post,
private_message::PrivateMessage,
},
+ traits::Crud,
};
use lemmy_utils::{apub::generate_actor_keypair, LemmyError};
use log::info;
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::{
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};