The Range class provides generic range values for representing inclusive or exclusive ranges of ordered data types.
Import:
Source: value/range.ts
Type parameters
Beg- The type of the beginning boundEnd- The type of the ending bound
Constructor
new Range(begin, end)
Create a new range value.
Parameters
| Parameter | Type | Description |
|---|---|---|
begin | Bound<Beg> | The beginning bound (can be inclusive or exclusive). |
end | Bound<End> | The ending bound (can be inclusive or exclusive). |
Examples
Properties
begin
The beginning bound of the range.
Type: Bound<Beg>
end
The ending bound of the range.
Type: Bound<End>
Instance methods
.toString()
Convert to string representation.
Returns
string - Range string (e.g., 1..10, 1..=10, 1>..10)
Examples
.toJSON()
Serialize for JSON.
Returns
string - Range string representation
.equals(other)
Check if two ranges are equal.
Returns
boolean - True if equal
Complete examples
Numeric ranges
Date ranges
Price ranges
Score ranges
Time-based filtering
Pagination with ID ranges
Exclusive ranges
Half-open ranges
Multiple ranges
Range queries in application
Range notation
SurrealDB uses specific notation for ranges:
| Notation | Description | Example |
|---|---|---|
a..=b | Inclusive both ends [a, b] | 1..=10 |
a..b | Inclusive start, exclusive end [a, b) | 1..10 |
a>..b | Exclusive start, exclusive end (a, b) | 1>..10 |
a>..=b | Exclusive start, inclusive end (a, b] | 1>..=10 |
Best practices
1. Use appropriate inclusivity
2. Type safety
3. Validate bounds
Use cases
Filtering - Filter records by numeric, date, or other ordered values
Pagination - Query records in ID ranges
Time Windows - Define time-based query windows
Price Filtering - E-commerce price range searches
Score Categorization - Categorize by score ranges (grades, ratings)
Geographic Bounds - Coordinate ranges for maps
See also
RecordIdRange - Range of record IDs
DateTime - Datetime values for date ranges
Decimal - Precise numbers for price ranges
Data Types Overview - All custom data types
SurrealQL Ranges - Database range syntax