Python sqlalchemy.sql.operators.json_getitem_op() Examples

The following are 7 code examples of sqlalchemy.sql.operators.json_getitem_op(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.sql.operators , or try the search function .
Example #1
Source File: tables.py    From ivre with GNU General Public License v3.0 7 votes vote down vote up
def extend_binary_expression(element, compiler, **kwargs):
    if isinstance(element.operator, custom_op):
        opstring = element.operator.opstring
        if opstring == '~':
            return compiler.process(func.REGEXP(element.left, element.right))
        if opstring == '~*':
            return compiler.process(func.IREGEXP(element.left, element.right))
        if opstring == '->':
            return compiler.process(func.ACCESS(element.left, element.right))
        if opstring == '->>':
            return compiler.process(func.ACCESS_TXT(element.left,
                                                    element.right))
        if opstring == '?':
            return compiler.process(func.HAS_KEY(element.left, element.right))
    # FIXME: Variant base type Comparator seems to be used here.
    if element.operator is json_getitem_op:
        return compiler.process(func.ACCESS(element.left, element.right))
    return compiler.visit_binary(element)


# Types 
Example #2
Source File: sqltypes.py    From planespotter with MIT License 6 votes vote down vote up
def _setup_getitem(self, default_comparator, index):
            if not isinstance(index, util.string_types) and \
                    isinstance(index, collections.Sequence):
                index = default_comparator._check_literal(
                    self.expr, operators.json_path_getitem_op,
                    index, bindparam_type=JSON.JSONPathType
                )

                operator = operators.json_path_getitem_op
            else:
                index = default_comparator._check_literal(
                    self.expr, operators.json_getitem_op,
                    index, bindparam_type=JSON.JSONIndexType
                )
                operator = operators.json_getitem_op

            return operator, index, self.type 
Example #3
Source File: sqltypes.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
def _setup_getitem(self, default_comparator, index):
            if not isinstance(index, util.string_types) and \
                    isinstance(index, collections.Sequence):
                index = default_comparator._check_literal(
                    self.expr, operators.json_path_getitem_op,
                    index, bindparam_type=JSON.JSONPathType
                )

                operator = operators.json_path_getitem_op
            else:
                index = default_comparator._check_literal(
                    self.expr, operators.json_getitem_op,
                    index, bindparam_type=JSON.JSONIndexType
                )
                operator = operators.json_getitem_op

            return operator, index, self.type 
Example #4
Source File: sqltypes.py    From sqlalchemy with MIT License 6 votes vote down vote up
def _setup_getitem(self, index):
            if not isinstance(index, util.string_types) and isinstance(
                index, compat.collections_abc.Sequence
            ):
                index = coercions.expect(
                    roles.BinaryElementRole,
                    index,
                    expr=self.expr,
                    operator=operators.json_path_getitem_op,
                    bindparam_type=JSON.JSONPathType,
                )

                operator = operators.json_path_getitem_op
            else:
                index = coercions.expect(
                    roles.BinaryElementRole,
                    index,
                    expr=self.expr,
                    operator=operators.json_getitem_op,
                    bindparam_type=JSON.JSONIndexType,
                )
                operator = operators.json_getitem_op

            return operator, index, self.type 
Example #5
Source File: sqltypes.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def _setup_getitem(self, default_comparator, index):
            if not isinstance(index, util.string_types) and \
                    isinstance(index, collections.Sequence):
                index = default_comparator._check_literal(
                    self.expr, operators.json_path_getitem_op,
                    index, bindparam_type=JSON.JSONPathType
                )

                operator = operators.json_path_getitem_op
            else:
                index = default_comparator._check_literal(
                    self.expr, operators.json_getitem_op,
                    index, bindparam_type=JSON.JSONIndexType
                )
                operator = operators.json_getitem_op

            return operator, index, self.type 
Example #6
Source File: sqltypes.py    From android_universal with MIT License 6 votes vote down vote up
def _setup_getitem(self, default_comparator, index):
            if not isinstance(index, util.string_types) and \
                    isinstance(index, collections.Sequence):
                index = default_comparator._check_literal(
                    self.expr, operators.json_path_getitem_op,
                    index, bindparam_type=JSON.JSONPathType
                )

                operator = operators.json_path_getitem_op
            else:
                index = default_comparator._check_literal(
                    self.expr, operators.json_getitem_op,
                    index, bindparam_type=JSON.JSONIndexType
                )
                operator = operators.json_getitem_op

            return operator, index, self.type 
Example #7
Source File: sqltypes.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _binary_w_type(self, typ, method_name):
            if not isinstance(
                self.expr, elements.BinaryExpression
            ) or self.expr.operator not in (
                operators.json_getitem_op,
                operators.json_path_getitem_op,
            ):
                raise exc.InvalidRequestError(
                    "The JSON cast operator JSON.%s() only works with a JSON "
                    "index expression e.g. col['q'].%s()"
                    % (method_name, method_name)
                )
            expr = self.expr._clone()
            expr.type = typ
            return expr