Make range types use SA range types
This commit is contained in:
@@ -5,6 +5,7 @@ Range data types
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DateRangeType
|
DateRangeType
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
@@ -28,3 +29,9 @@ NumericRangeType
|
|||||||
|
|
||||||
.. autoclass:: NumericRangeType
|
.. autoclass:: NumericRangeType
|
||||||
|
|
||||||
|
|
||||||
|
RangeComparator
|
||||||
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. autoclass:: RangeComparator
|
||||||
|
:members:
|
||||||
|
@@ -49,10 +49,6 @@ from .types import (
|
|||||||
TSVectorType,
|
TSVectorType,
|
||||||
URLType,
|
URLType,
|
||||||
UUIDType,
|
UUIDType,
|
||||||
INT4RANGE,
|
|
||||||
INT8RANGE,
|
|
||||||
DATERANGE,
|
|
||||||
NUMRANGE,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -111,8 +107,4 @@ __all__ = (
|
|||||||
TSVectorType,
|
TSVectorType,
|
||||||
URLType,
|
URLType,
|
||||||
UUIDType,
|
UUIDType,
|
||||||
INT4RANGE,
|
|
||||||
INT8RANGE,
|
|
||||||
DATERANGE,
|
|
||||||
NUMRANGE,
|
|
||||||
)
|
)
|
||||||
|
@@ -9,10 +9,6 @@ from .ip_address import IPAddressType
|
|||||||
from .json import JSONType
|
from .json import JSONType
|
||||||
from .locale import LocaleType
|
from .locale import LocaleType
|
||||||
from .range import (
|
from .range import (
|
||||||
INT4RANGE,
|
|
||||||
INT8RANGE,
|
|
||||||
DATERANGE,
|
|
||||||
NUMRANGE,
|
|
||||||
DateRangeType,
|
DateRangeType,
|
||||||
DateTimeRangeType,
|
DateTimeRangeType,
|
||||||
IntRangeType,
|
IntRangeType,
|
||||||
@@ -56,10 +52,6 @@ __all__ = (
|
|||||||
WeekDay,
|
WeekDay,
|
||||||
WeekDays,
|
WeekDays,
|
||||||
WeekDaysType,
|
WeekDaysType,
|
||||||
INT4RANGE,
|
|
||||||
INT8RANGE,
|
|
||||||
DATERANGE,
|
|
||||||
NUMRANGE,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -35,9 +35,6 @@ It is essentially the same as:
|
|||||||
session.query(Car).filter(Car.price_range == DecimalInterval([300, 300]))
|
session.query(Car).filter(Car.price_range == DecimalInterval([300, 300]))
|
||||||
|
|
||||||
|
|
||||||
The coercion is provided for convenience.
|
|
||||||
|
|
||||||
|
|
||||||
Comparison operators
|
Comparison operators
|
||||||
^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
@@ -78,53 +75,17 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
import six
|
import six
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy.dialects.postgresql.base import ischema_names
|
from sqlalchemy.dialects.postgresql import (
|
||||||
|
INT4RANGE,
|
||||||
|
DATERANGE,
|
||||||
|
NUMRANGE,
|
||||||
|
TSRANGE,
|
||||||
|
)
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
from ..exceptions import ImproperlyConfigured
|
from ..exceptions import ImproperlyConfigured
|
||||||
from .scalar_coercible import ScalarCoercible
|
from .scalar_coercible import ScalarCoercible
|
||||||
|
|
||||||
|
|
||||||
class INT4RANGE(types.UserDefinedType):
|
|
||||||
"""
|
|
||||||
Raw number range type, only supports PostgreSQL for now.
|
|
||||||
"""
|
|
||||||
def get_col_spec(self):
|
|
||||||
return 'int4range'
|
|
||||||
|
|
||||||
|
|
||||||
class INT8RANGE(types.UserDefinedType):
|
|
||||||
def get_col_spec(self):
|
|
||||||
return 'int8range'
|
|
||||||
|
|
||||||
|
|
||||||
class NUMRANGE(types.UserDefinedType):
|
|
||||||
def get_col_spec(self):
|
|
||||||
return 'numrange'
|
|
||||||
|
|
||||||
|
|
||||||
class DATERANGE(types.UserDefinedType):
|
|
||||||
def get_col_spec(self):
|
|
||||||
return 'daterange'
|
|
||||||
|
|
||||||
|
|
||||||
class TSRANGE(types.UserDefinedType):
|
|
||||||
def get_col_spec(self):
|
|
||||||
return 'tsrange'
|
|
||||||
|
|
||||||
|
|
||||||
class TSTZRANGE(types.UserDefinedType):
|
|
||||||
def get_col_spec(self):
|
|
||||||
return 'tstzrange'
|
|
||||||
|
|
||||||
|
|
||||||
ischema_names['int4range'] = INT4RANGE
|
|
||||||
ischema_names['int8range'] = INT8RANGE
|
|
||||||
ischema_names['numrange'] = NUMRANGE
|
|
||||||
ischema_names['daterange'] = DATERANGE
|
|
||||||
ischema_names['tsrange'] = TSRANGE
|
|
||||||
ischema_names['tstzrange'] = TSTZRANGE
|
|
||||||
|
|
||||||
|
|
||||||
class RangeComparator(types.TypeEngine.Comparator):
|
class RangeComparator(types.TypeEngine.Comparator):
|
||||||
@classmethod
|
@classmethod
|
||||||
def coerced_func(cls, func):
|
def coerced_func(cls, func):
|
||||||
@@ -163,10 +124,22 @@ class RangeComparator(types.TypeEngine.Comparator):
|
|||||||
return super(RangeComparator, self).notin_(other)
|
return super(RangeComparator, self).notin_(other)
|
||||||
|
|
||||||
def __rshift__(self, other, **kwargs):
|
def __rshift__(self, other, **kwargs):
|
||||||
|
"""
|
||||||
|
Returns whether or not given interval is strictly right of another
|
||||||
|
interval.
|
||||||
|
|
||||||
|
[a, b] >> [c, d] True, if a > d
|
||||||
|
"""
|
||||||
other = self.coerce_arg(other)
|
other = self.coerce_arg(other)
|
||||||
return self.op('>>')(other)
|
return self.op('>>')(other)
|
||||||
|
|
||||||
def __lshift__(self, other, **kwargs):
|
def __lshift__(self, other, **kwargs):
|
||||||
|
"""
|
||||||
|
Returns whether or not given interval is strictly left of another
|
||||||
|
interval.
|
||||||
|
|
||||||
|
[a, b] << [c, d] True, if b < c
|
||||||
|
"""
|
||||||
other = self.coerce_arg(other)
|
other = self.coerce_arg(other)
|
||||||
return self.op('<<')(other)
|
return self.op('<<')(other)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user