docs.rs failed to build sql-values-0.3.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: sql-values-0.8.0

sql-values

crates.io docs.rs CI Codecov MSRV license

sql-values holds the semantics of SQL values. It ports PostgreSQL's own value rules (input, canonical output, order, arithmetic and the explicit cast of a literal), each checked against PostgreSQL 18, and it reads the text forms PostgreSQL, MySQL and SQLite emit for scalar values, so every wire-text consumer decodes the same spelling to the same Rust value.

use sql_values::{
    CastTarget, IntervalError, Literal, cast_literal, parse_bool, parse_interval, parse_timestamp,
};

assert_eq!(parse_bool("t"), Some(true));

let span = parse_interval("1.5 days").unwrap();
assert_eq!(span.to_string(), "1 day 12:00:00");
assert_eq!(parse_interval("p1d"), Err(IntervalError::InvalidSyntax));

let at = parse_timestamp("2024-01-31 10:00:00").unwrap();
let month = parse_interval("1 mon").unwrap();
assert_eq!(month.add_to_timestamp(at).unwrap().to_string(), "2024-02-29 10:00:00");

let level = cast_literal(Literal::Number("2.7"), CastTarget::Integer).unwrap();
assert_eq!(level.to_string(), "3");

The crate supports no_std. Decimal parsing is available through the decimal feature, and serde derives for interval values through the serde feature.