4 use chrono::NaiveDateTime;
8 serialize::{Output, ToSql},
13 fmt::{Display, Formatter},
21 #[derive(Clone, PartialEq, Serialize, Debug, AsExpression, FromSqlRow)]
23 pub struct Url(url::Url);
25 impl<DB: Backend> ToSql<Text, DB> for Url
27 String: ToSql<Text, DB>,
29 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
30 self.0.to_string().to_sql(out)
34 impl<DB: Backend> FromSql<Text, DB> for Url
36 String: FromSql<Text, DB>,
38 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
39 let str = String::from_sql(bytes)?;
40 Ok(Url(url::Url::parse(&str)?))
45 pub fn into_inner(self) -> url::Url {
50 impl Display for Url {
51 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
52 self.to_owned().into_inner().fmt(f)
56 impl From<Url> for url::Url {
57 fn from(url: Url) -> Self {
62 impl From<url::Url> for Url {
63 fn from(url: url::Url) -> Self {
68 // TODO: can probably move this back to lemmy_db_queries
69 pub fn naive_now() -> NaiveDateTime {
70 chrono::prelude::Utc::now().naive_utc()