Allow SELECT statements to START AT 0

Closes #1516
This commit is contained in:
Tobie Morgan Hitchcock 2022-12-09 16:02:36 +00:00
parent 59dcc44883
commit dcc28a6ec7
3 changed files with 37 additions and 1 deletions

View file

@ -235,6 +235,30 @@ impl Number {
}
}
pub fn is_negative(&self) -> bool {
match self {
Number::Int(v) => v < &0,
Number::Float(v) => v < &0.0,
Number::Decimal(v) => v < &BigDecimal::from(0),
}
}
pub fn is_zero_or_positive(&self) -> bool {
match self {
Number::Int(v) => v >= &0,
Number::Float(v) => v >= &0.0,
Number::Decimal(v) => v >= &BigDecimal::from(0),
}
}
pub fn is_zero_or_negative(&self) -> bool {
match self {
Number::Int(v) => v <= &0,
Number::Float(v) => v <= &0.0,
Number::Decimal(v) => v <= &BigDecimal::from(0),
}
}
// -----------------------------------
// Simple conversion of number
// -----------------------------------

View file

@ -23,7 +23,7 @@ impl Start {
doc: Option<&Value>,
) -> Result<usize, Error> {
match self.0.compute(ctx, opt, txn, doc).await {
Ok(v) if v.is_integer() && v.is_positive() => Ok(v.as_usize()),
Ok(v) if v.is_integer() && v.is_zero_or_positive() => Ok(v.as_usize()),
Ok(v) => Err(Error::InvalidStart {
value: v.as_string(),
}),

View file

@ -698,6 +698,18 @@ impl Value {
matches!(self, Value::Number(v) if v.is_positive())
}
pub fn is_negative(&self) -> bool {
matches!(self, Value::Number(v) if v.is_negative())
}
pub fn is_zero_or_positive(&self) -> bool {
matches!(self, Value::Number(v) if v.is_zero_or_positive())
}
pub fn is_zero_or_negative(&self) -> bool {
matches!(self, Value::Number(v) if v.is_zero_or_negative())
}
pub fn is_datetime(&self) -> bool {
matches!(self, Value::Datetime(_))
}