Trait diesel::pg::expression::extensions::DayAndMonthIntervalDsl postgres
[−]
[src]
pub trait DayAndMonthIntervalDsl: Sized + Mul<Self, Output = Self> { fn days(self) -> PgInterval; fn months(self) -> PgInterval; fn weeks(self) -> PgInterval { ... } fn years(self) -> PgInterval { ... } fn day(self) -> PgInterval { ... } fn week(self) -> PgInterval { ... } fn month(self) -> PgInterval { ... } fn year(self) -> PgInterval { ... } }
A DSL added to i32
and f64
to construct PostgreSQL intervals of greater
than 1 day.
The behavior of these methods when called on NAN
or Infinity
is
undefined.
Example
connection.execute("INSERT INTO users (name, created_at) VALUES ('Sean', NOW()), ('Tess', NOW() - '5 days'::interval), ('Jim', NOW() - '10 days'::interval)").unwrap(); let mut data: Vec<String> = users .select(name) .filter(created_at.gt(now - 7.days())) .load(&connection).unwrap(); assert_eq!(2, data.len()); assert_eq!("Sean".to_string(), data[0]); assert_eq!("Tess".to_string(), data[1]);
Required Methods
fn days(self) -> PgInterval
Returns a PgInterval representing self
in days
fn months(self) -> PgInterval
Returns a PgInterval representing self
in monhts
Provided Methods
fn weeks(self) -> PgInterval
Returns a PgInterval representing self
in weeks
Note: When called on a high precision float, the returned interval may be 1 microsecond different than the equivalent string passed to PostgreSQL.
fn years(self) -> PgInterval
Returns a PgInterval representing self
in weeks
Note: When called on a float, this method will mimic the behavior of PostgreSQL's interval parsing, and will ignore units smaller than months.
assert_eq!(1.08.years(), 1.year()); assert_eq!(1.09.years(), 1.year() + 1.month());
fn day(self) -> PgInterval
Identical to days
fn week(self) -> PgInterval
Identical to weeks
fn month(self) -> PgInterval
Identical to months
fn year(self) -> PgInterval
Identical to years