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);
71 #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
73 pub struct DbUrl(Url);
75 impl<DB: Backend> ToSql<Text, DB> for DbUrl
77 String: ToSql<Text, DB>,
79 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
80 self.0.to_string().to_sql(out)
84 impl<DB: Backend> FromSql<Text, DB> for DbUrl
86 String: FromSql<Text, DB>,
88 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
89 let str = String::from_sql(bytes)?;
90 Ok(DbUrl(Url::parse(&str)?))
95 pub fn into_inner(self) -> Url {
100 impl Display for DbUrl {
101 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
102 self.to_owned().into_inner().fmt(f)
106 impl From<DbUrl> for Url {
107 fn from(url: DbUrl) -> Self {
112 impl From<Url> for DbUrl {
113 fn from(url: Url) -> Self {
118 // TODO: can probably move this back to lemmy_db_queries
119 pub fn naive_now() -> NaiveDateTime {
120 chrono::prelude::Utc::now().naive_utc()