homestar_runtime/db/
utils.rs

1//! Utility functions Database interaction.
2
3use chrono::{DateTime, NaiveDateTime};
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7/// Trait for converting nanoseconds to a timestamp.
8#[allow(dead_code)]
9pub(crate) trait Timestamp {
10    fn timestamp_from_nanos(&self) -> Option<NaiveDateTime>;
11}
12
13impl Timestamp for i64 {
14    fn timestamp_from_nanos(&self) -> Option<NaiveDateTime> {
15        let nanos = self % 1_000_000_000;
16        let seconds = (self - nanos) / 1_000_000_000;
17        let dt = DateTime::from_timestamp(seconds, nanos as u32);
18        dt.map(|dt| dt.naive_utc())
19    }
20}
21
22/// Health status of the server and database connection.
23#[derive(Debug, Serialize, Deserialize, JsonSchema)]
24#[schemars(rename = "health")]
25pub struct Health {
26    /// Health status.
27    pub healthy: bool,
28}