Skip to main content

dbkit_core/
interval.rs

1use crate::expr::{Expr, ExprNode, IntervalField, IntoExpr, NumericExprType};
2use crate::PgInterval;
3
4fn interval_part<T>(field: IntervalField, value: impl IntoExpr<T>) -> Expr<PgInterval> {
5    let value = value.into_expr();
6    Expr::new(ExprNode::MakeInterval {
7        field,
8        value: Box::new(value.node),
9    })
10}
11
12pub fn days(value: impl IntoExpr<i32>) -> Expr<PgInterval> {
13    interval_part(IntervalField::Days, value)
14}
15
16pub fn hours(value: impl IntoExpr<i32>) -> Expr<PgInterval> {
17    interval_part(IntervalField::Hours, value)
18}
19
20pub fn minutes(value: impl IntoExpr<i32>) -> Expr<PgInterval> {
21    interval_part(IntervalField::Minutes, value)
22}
23
24pub fn seconds<T>(value: impl IntoExpr<T>) -> Expr<PgInterval>
25where
26    T: NumericExprType,
27{
28    interval_part(IntervalField::Seconds, value)
29}