From af9bd5b62fcd15bc839d620c2ae6f98cff139fca Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sun, 30 Oct 2022 01:30:21 +0000 Subject: [PATCH] Support path expressions after Record IDs with integer IDs --- lib/src/sql/ending.rs | 1 + lib/src/sql/number.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/sql/ending.rs b/lib/src/sql/ending.rs index 039cdd41..b7500fb0 100644 --- a/lib/src/sql/ending.rs +++ b/lib/src/sql/ending.rs @@ -21,6 +21,7 @@ pub fn number(i: &str) -> IResult<&str, ()> { map(char('"'), |_| ()), map(char('\''), |_| ()), map(char(';'), |_| ()), + map(char('.'), |_| ()), map(char(','), |_| ()), map(tag(".."), |_| ()), map(eof, |_| ()), diff --git a/lib/src/sql/number.rs b/lib/src/sql/number.rs index fe8d7481..b8d697a7 100644 --- a/lib/src/sql/number.rs +++ b/lib/src/sql/number.rs @@ -105,7 +105,13 @@ impl From for Number { impl From<&str> for Number { fn from(s: &str) -> Self { - Self::Decimal(BigDecimal::from_str(s).unwrap_or_default()) + // Attempt to parse as i64 + match s.parse::() { + // Store it as an i64 + Ok(v) => Self::Int(v), + // It wasn't parsed as a i64 so store as a decimal + _ => Self::Decimal(BigDecimal::from_str(s).unwrap_or_default()), + } } } @@ -607,7 +613,7 @@ impl Sort for Vec { } pub fn number(i: &str) -> IResult<&str, Number> { - alt((map(integer, Number::from), map(decimal, Number::from)))(i) + alt((map(decimal, Number::from), map(integer, Number::from)))(i) } pub fn integer(i: &str) -> IResult<&str, i64> {