bestool_postgres/
pg_interval.rs

1use std::{error::Error, time::Duration};
2
3use bytes::{BufMut, BytesMut};
4use tokio_postgres::types::{IsNull, ToSql, Type};
5
6#[derive(Debug)]
7pub struct Interval(pub Duration);
8
9impl ToSql for Interval {
10	fn to_sql(&self, _: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
11		out.put_i64(self.0.as_micros().try_into().unwrap_or_default());
12		out.put_i32(0);
13		out.put_i32(0);
14		Ok(IsNull::No)
15	}
16
17	fn accepts(ty: &Type) -> bool {
18		matches!(*ty, Type::INTERVAL)
19	}
20
21	tokio_postgres::types::to_sql_checked!();
22}