Range<Beg, End>
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