Skip to content

Commit fc2c326

Browse files
committed
Add in_range operator
1 parent d3288f0 commit fc2c326

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

terminusdb_client/woqlquery/woql_query.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,34 @@ def lte(self, left, right):
22322232
self._cursor["right"] = self._clean_object(right)
22332233
return self
22342234

2235+
def in_range(self, value, start, end):
2236+
"""Tests whether a value falls within a half-open range [start, end).
2237+
Succeeds if start <= value < end.
2238+
2239+
Parameters
2240+
----------
2241+
value : str or number
2242+
the value to test
2243+
start : str or number
2244+
the inclusive lower bound
2245+
end : str or number
2246+
the exclusive upper bound
2247+
2248+
Returns
2249+
-------
2250+
WOQLQuery object
2251+
query object that can be chained and/or execute
2252+
"""
2253+
if value is None or start is None or end is None:
2254+
raise ValueError("InRange takes three parameters")
2255+
if self._cursor.get("@type"):
2256+
self._wrap_cursor_with_and()
2257+
self._cursor["@type"] = "InRange"
2258+
self._cursor["value"] = self._clean_object(value)
2259+
self._cursor["start"] = self._clean_object(start)
2260+
self._cursor["end"] = self._clean_object(end)
2261+
return self
2262+
22352263
def opt(self, query=None):
22362264
"""The Query in the Optional argument is specified as optional
22372265

0 commit comments

Comments
 (0)