diesel/expression/functions/
date_and_time.rs1use backend::Backend;
2use expression::coerce::Coerce;
3use expression::{AsExpression, Expression, NonAggregate};
4use query_builder::*;
5use result::QueryResult;
6use sql_types::*;
7
8#[allow(non_camel_case_types)]
11#[derive(Debug, Copy, Clone, QueryId)]
12pub struct now;
13
14impl Expression for now {
15 type SqlType = Timestamp;
16}
17
18impl NonAggregate for now {}
19
20impl<DB: Backend> QueryFragment<DB> for now {
21 fn walk_ast(&self, mut out: AstPass<DB>) -> QueryResult<()> {
22 out.push_sql("CURRENT_TIMESTAMP");
23 Ok(())
24 }
25}
26
27impl_selectable_expression!(now);
28
29operator_allowed!(now, Add, add);
30operator_allowed!(now, Sub, sub);
31sql_function! {
32 fn date(expr: Timestamp) -> Date;
49}
50
51impl AsExpression<Nullable<Timestamp>> for now {
52 type Expression = Coerce<now, Nullable<Timestamp>>;
53
54 fn as_expression(self) -> Self::Expression {
55 Coerce::new(self)
56 }
57}
58
59#[cfg(feature = "postgres")]
60impl AsExpression<Timestamptz> for now {
61 type Expression = Coerce<now, Timestamptz>;
62
63 fn as_expression(self) -> Self::Expression {
64 Coerce::new(self)
65 }
66}
67
68#[cfg(feature = "postgres")]
69impl AsExpression<Nullable<Timestamptz>> for now {
70 type Expression = Coerce<now, Nullable<Timestamptz>>;
71
72 fn as_expression(self) -> Self::Expression {
73 Coerce::new(self)
74 }
75}