sql-values 0.5.0

SQL values, with PostgreSQL's value rules beside readers of the text PostgreSQL, MySQL and SQLite emit
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use sql_values::{PgDate, PgTime, PgTimestamp, parse_timestamp};

/// Assert each case's text parses as 2024-01-15 10:30:45 plus `frac_ns` nanoseconds.
pub fn assert_fractional_seconds(cases: &[(&str, u32)], mut fetch: impl FnMut(&str) -> String) {
    for &(expr, frac_ns) in cases {
        let text = fetch(expr);
        let expected = PgTimestamp::new(
            PgDate::from_ymd(2024, 1, 15).unwrap(),
            PgTime::from_hms_micro(10, 30, 45, frac_ns / 1_000).unwrap(),
        )
        .unwrap();
        let got = parse_timestamp(&text)
            .unwrap_or_else(|| panic!("parse_timestamp: {text:?} (expr={expr})"));
        assert_eq!(got, expected, "expr={expr} text={text:?}");
    }
}