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);
77 #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
79 pub struct DbUrl(Url);
81 impl<DB: Backend> ToSql<Text, DB> for DbUrl
83 String: ToSql<Text, DB>,
85 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
86 self.0.to_string().to_sql(out)
90 impl<DB: Backend> FromSql<Text, DB> for DbUrl
92 String: FromSql<Text, DB>,
94 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
95 let str = String::from_sql(bytes)?;
96 Ok(DbUrl(Url::parse(&str)?))
101 // TODO: remove this method and just use into()
102 pub fn into_inner(self) -> Url {
107 impl Display for DbUrl {
108 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
109 self.to_owned().0.fmt(f)
113 impl From<DbUrl> for Url {
114 fn from(url: DbUrl) -> Self {
119 impl From<Url> for DbUrl {
120 fn from(url: Url) -> Self {
125 // TODO: can probably move this back to lemmy_db_queries
126 pub fn naive_now() -> NaiveDateTime {
127 chrono::prelude::Utc::now().naive_utc()