5 extern crate diesel_derive_newtype;
7 use chrono::NaiveDateTime;
11 serialize::{Output, ToSql},
14 use serde::{Deserialize, Serialize};
17 fmt::{Display, Formatter},
26 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
28 pub struct PostId(pub i32);
30 impl fmt::Display for PostId {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "{}", self.0)
37 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
39 pub struct PersonId(pub i32);
41 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
42 pub struct CommentId(pub i32);
44 impl fmt::Display for CommentId {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 write!(f, "{}", self.0)
51 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
53 pub struct CommunityId(pub i32);
55 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
56 pub struct LocalUserId(pub i32);
58 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
59 pub struct PrivateMessageId(i32);
61 impl fmt::Display for PrivateMessageId {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 write!(f, "{}", self.0)
67 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
68 pub struct PersonMentionId(i32);
70 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
71 pub struct PersonBlockId(i32);
73 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
74 pub struct CommunityBlockId(i32);
76 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
77 pub struct CommentReportId(i32);
79 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
80 pub struct PostReportId(i32);
83 #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
85 pub struct DbUrl(Url);
87 impl<DB: Backend> ToSql<Text, DB> for DbUrl
89 String: ToSql<Text, DB>,
91 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
92 self.0.to_string().to_sql(out)
96 impl<DB: Backend> FromSql<Text, DB> for DbUrl
98 String: FromSql<Text, DB>,
100 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
101 let str = String::from_sql(bytes)?;
102 Ok(DbUrl(Url::parse(&str)?))
107 // TODO: remove this method and just use into()
108 pub fn into_inner(self) -> Url {
113 impl Display for DbUrl {
114 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
115 self.to_owned().0.fmt(f)
119 impl From<DbUrl> for Url {
120 fn from(url: DbUrl) -> Self {
125 impl From<Url> for DbUrl {
126 fn from(url: Url) -> Self {
131 // TODO: can probably move this back to lemmy_db_queries
132 pub fn naive_now() -> NaiveDateTime {
133 chrono::prelude::Utc::now().naive_utc()