Skip to main content

loopflow/store/
rows.rs

1use crate::store::StoreResult;
2use crate::work::wave::Wave;
3
4pub fn unix_to_datetime(seconds: i64) -> time::OffsetDateTime {
5    time::OffsetDateTime::from_unix_timestamp(seconds).unwrap_or(time::OffsetDateTime::UNIX_EPOCH)
6}
7
8pub fn now_unix() -> i64 {
9    time::OffsetDateTime::now_utc().unix_timestamp()
10}
11
12/// SELECT id, name, repo, created_at, parent_wave_id, promoted_at,
13///        retired_at, superseded_by_wave_id, retirement_reason
14pub fn map_wave_row(row: &rusqlite::Row<'_>) -> StoreResult<Wave> {
15    Ok(Wave::from_stored_parts(
16        row.get(0)?,
17        row.get(1)?,
18        row.get(2)?,
19        unix_to_datetime(row.get(3)?),
20        row.get(4)?,
21        row.get::<_, Option<i64>>(5)?.map(unix_to_datetime),
22        row.get::<_, Option<i64>>(6)?.map(unix_to_datetime),
23        row.get(7)?,
24        row.get(8)?,
25    )
26    .with_slug(row.get(9)?))
27}