Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/ranges.py : 70%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (C) 2013-2020 the SQLAlchemy authors and contributors
2# <see AUTHORS file>
3#
4# This module is part of SQLAlchemy and is released under
5# the MIT License: http://www.opensource.org/licenses/mit-license.php
7from ... import types as sqltypes
10__all__ = ("INT4RANGE", "INT8RANGE", "NUMRANGE")
13class RangeOperators(object):
14 """
15 This mixin provides functionality for the Range Operators
16 listed in Table 9-44 of the `postgres documentation`__ for Range
17 Functions and Operators. It is used by all the range types
18 provided in the ``postgres`` dialect and can likely be used for
19 any range types you create yourself.
21 __ http://www.postgresql.org/docs/devel/static/functions-range.html
23 No extra support is provided for the Range Functions listed in
24 Table 9-45 of the postgres documentation. For these, the normal
25 :func:`~sqlalchemy.sql.expression.func` object should be used.
27 """
29 class comparator_factory(sqltypes.Concatenable.Comparator):
30 """Define comparison operations for range types."""
32 def __ne__(self, other):
33 "Boolean expression. Returns true if two ranges are not equal"
34 if other is None:
35 return super(RangeOperators.comparator_factory, self).__ne__(
36 other
37 )
38 else:
39 return self.expr.op("<>")(other)
41 def contains(self, other, **kw):
42 """Boolean expression. Returns true if the right hand operand,
43 which can be an element or a range, is contained within the
44 column.
45 """
46 return self.expr.op("@>")(other)
48 def contained_by(self, other):
49 """Boolean expression. Returns true if the column is contained
50 within the right hand operand.
51 """
52 return self.expr.op("<@")(other)
54 def overlaps(self, other):
55 """Boolean expression. Returns true if the column overlaps
56 (has points in common with) the right hand operand.
57 """
58 return self.expr.op("&&")(other)
60 def strictly_left_of(self, other):
61 """Boolean expression. Returns true if the column is strictly
62 left of the right hand operand.
63 """
64 return self.expr.op("<<")(other)
66 __lshift__ = strictly_left_of
68 def strictly_right_of(self, other):
69 """Boolean expression. Returns true if the column is strictly
70 right of the right hand operand.
71 """
72 return self.expr.op(">>")(other)
74 __rshift__ = strictly_right_of
76 def not_extend_right_of(self, other):
77 """Boolean expression. Returns true if the range in the column
78 does not extend right of the range in the operand.
79 """
80 return self.expr.op("&<")(other)
82 def not_extend_left_of(self, other):
83 """Boolean expression. Returns true if the range in the column
84 does not extend left of the range in the operand.
85 """
86 return self.expr.op("&>")(other)
88 def adjacent_to(self, other):
89 """Boolean expression. Returns true if the range in the column
90 is adjacent to the range in the operand.
91 """
92 return self.expr.op("-|-")(other)
94 def __add__(self, other):
95 """Range expression. Returns the union of the two ranges.
96 Will raise an exception if the resulting range is not
97 contigous.
98 """
99 return self.expr.op("+")(other)
102class INT4RANGE(RangeOperators, sqltypes.TypeEngine):
103 """Represent the PostgreSQL INT4RANGE type.
105 """
107 __visit_name__ = "INT4RANGE"
110class INT8RANGE(RangeOperators, sqltypes.TypeEngine):
111 """Represent the PostgreSQL INT8RANGE type.
113 """
115 __visit_name__ = "INT8RANGE"
118class NUMRANGE(RangeOperators, sqltypes.TypeEngine):
119 """Represent the PostgreSQL NUMRANGE type.
121 """
123 __visit_name__ = "NUMRANGE"
126class DATERANGE(RangeOperators, sqltypes.TypeEngine):
127 """Represent the PostgreSQL DATERANGE type.
129 """
131 __visit_name__ = "DATERANGE"
134class TSRANGE(RangeOperators, sqltypes.TypeEngine):
135 """Represent the PostgreSQL TSRANGE type.
137 """
139 __visit_name__ = "TSRANGE"
142class TSTZRANGE(RangeOperators, sqltypes.TypeEngine):
143 """Represent the PostgreSQL TSTZRANGE type.
145 """
147 __visit_name__ = "TSTZRANGE"