File tree Expand file tree Collapse file tree
diesel_tests/tests/expressions
diesel/src/expression/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,3 +69,12 @@ impl AsExpression<Timestamptz> for now {
6969 Coerce :: new ( self )
7070 }
7171}
72+
73+ #[ cfg( feature="postgres" ) ]
74+ impl AsExpression < Nullable < Timestamptz > > for now {
75+ type Expression = Coerce < now , Nullable < Timestamptz > > ;
76+
77+ fn as_expression ( self ) -> Self :: Expression {
78+ Coerce :: new ( self )
79+ }
80+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use schema::{connection, TestConnection};
22use diesel:: * ;
33use diesel:: data_types:: * ;
44use diesel:: expression:: dsl:: * ;
5+ use diesel:: types:: Nullable ;
56
67table ! {
78 has_timestamps {
@@ -59,6 +60,25 @@ fn now_can_be_used_as_timestamptz() {
5960 assert_eq ! ( Ok ( vec![ 1 ] ) , before_now) ;
6061}
6162
63+ #[ test]
64+ #[ cfg( feature = "postgres" ) ]
65+ // FIXME: Replace this with an actual timestamptz expression
66+ fn now_can_be_used_as_nullable_timestamptz ( ) {
67+ use self :: has_timestamps:: dsl:: * ;
68+ use diesel:: types:: Timestamptz ;
69+
70+ let connection = connection ( ) ;
71+ setup_test_table ( & connection) ;
72+ connection. execute ( "INSERT INTO has_timestamps (created_at) VALUES \
73+ (NOW() - '1 day'::interval)") . unwrap ( ) ;
74+
75+ let created_at_tz = sql :: < Nullable < Timestamptz > > ( "created_at" ) ;
76+ let before_now = has_timestamps. select ( id)
77+ . filter ( created_at_tz. lt ( now) )
78+ . load :: < i32 > ( & connection) ;
79+ assert_eq ! ( Ok ( vec![ 1 ] ) , before_now) ;
80+ }
81+
6282#[ test]
6383#[ cfg( feature = "sqlite" ) ]
6484fn now_executes_sql_function_now ( ) {
You can’t perform that action at this time.
0 commit comments