use super::error::{ts_fail, NumericParseSnafu, Result};
use super::{
types::{AtomicType, Type},
Value,
};
pub fn parse_numeric_type(n: &str) -> Result<AtomicType> {
match parse_sql_number(n)?.type_() {
Type::Atom(t) => Ok(t),
t => ts_fail!("Expected atomic type after parsing number: {:?}", t),
}
}
pub fn parse_sql_number(n: &str) -> Result<Value> {
n.parse::<i64>()
.map(|i| Value::Int64(i))
.or_else(|_| n.parse::<f64>().map(|f| Value::Float64(f)))
.map_err(|_| NumericParseSnafu { val: n.to_string() }.build())
}