Ejemplo n.º 1
0
    async def upsert(self, space_name, tuple_value, op_list, **kwargs):
        index_name = kwargs.get("index", 0)

        if isinstance(space_name, str):
            sp = await self.schema.get_space(space_name)
            space_name = sp.sid

        if isinstance(index_name, str):
            idx = await self.schema.get_index(space_name, index_name)
            index_name = idx.iid

        res = await self._send_request(
            RequestUpsert(self, space_name, index_name, tuple_value, op_list))

        return res
Ejemplo n.º 2
0
try:
    s.send(bytes(request))
except OSError as e:
    print '   => ', 'Failed to send request'
response = Response(c, c._read_response())
print response.__str__()

request = RequestUpdate(c, 568, 0, [1], [['+', 2, 1], ['-', 3, 1]])
try:
    s.send(bytes(request))
except OSError as e:
    print '   => ', 'Failed to send request'
response = Response(c, c._read_response())
print response.__str__()

request = RequestUpsert(c, 568, 0, [1, 0, 0, 0], [['+', 2, 1], ['-', 3, 1]])
try:
    s.send(bytes(request))
except OSError as e:
    print '   => ', 'Failed to send request'
response = Response(c, c._read_response())

request = RequestSelect(c, 568, 0, [1], 0, 1, 0)
try:
    s.send(bytes(request))
except OSError as e:
    print '   => ', 'Failed to send request'
response = Response(c, c._read_response())
print response.__str__()

c.close()
Ejemplo n.º 3
0
try:
    s.send(bytes(request))
except OSError as e:
    print("   => ", "Failed to send request")
response = Response(c, c._read_response())
print(response.__str__())

request = RequestUpdate(c, 568, 0, [1], [["+", 2, 1], ["-", 3, 1]])
try:
    s.send(bytes(request))
except OSError as e:
    print("   => ", "Failed to send request")
response = Response(c, c._read_response())
print(response.__str__())

request = RequestUpsert(c, 568, 0, [1, 0, 0, 0], [["+", 2, 1], ["-", 3, 1]])
try:
    s.send(bytes(request))
except OSError as e:
    print("   => ", "Failed to send request")
response = Response(c, c._read_response())

request = RequestSelect(c, 568, 0, [1], 0, 1, 0)
try:
    s.send(bytes(request))
except OSError as e:
    print("   => ", "Failed to send request")
response = Response(c, c._read_response())
print(response.__str__())

c.close()
Ejemplo n.º 4
0
    def upsert(self, space_name, tuple_value, op_list, **kwargs):
        '''
        Execute UPSERT request.

        If there is an existing tuple which matches the key fields of
        `tuple_value`, then the request has the same effect as UPDATE
        and the [(field_1, symbol_1, arg_1), ...] parameter is used.

        If there is no existing tuple which matches the key fields of
        `tuple_value`, then the request has the same effect as INSERT
        and the `tuple_value` parameter is used. However, unlike insert
        or update, upsert will not read a tuple and perform error checks
        before returning -- this is a design feature which enhances
        throughput but requires more caution on the part of the user.

        If you're using secondary index, it must be unique.

        List of operations allows to update individual fields.

        *Allowed operations:*

        (For every operation you must provide field number, to apply this
        operation to)

        * `+` for addition (values must be numeric)
        * `-` for subtraction (values must be numeric)
        * `&` for bitwise AND (values must be unsigned numeric)
        * `|` for bitwise OR (values must be unsigned numeric)
        * `^` for bitwise XOR (values must be unsigned numeric)
        * `:` for string splice (you must provide `offset`, `count` and `value`
          for this operation)
        * `!` for insertion (provide any element to insert)
        * `=` for assignment (provide any element to assign)
        * `#` for deletion (provide count of fields to delete)

        :param space_name: space number or name to update a record
        :type space_name: int or str
        :param index: index number or name to update a record
        :type index: int or str
        :param tuple_value: tuple, that
        :type tuple_value:
        :param op_list: list of operations. Each operation
            is tuple of three (or more) values
        :type op_list: a list of the form [(symbol_1, field_1, arg_1),
            (symbol_2, field_2, arg_2_1, arg_2_2, arg_2_3),...]

        :rtype: `Response` instance

        Operation examples:

        .. code-block:: python

            # 'ADD' 55 to second field
            # Assign 'x' to third field
            [('+', 2, 55), ('=', 3, 'x')]
            # 'OR' third field with '1'
            # Cut three symbols starting from second and replace them with '!!'
            # Insert 'hello, world' field before fifth element of tuple
            [('|', 3, 1), (':', 2, 2, 3, '!!'), ('!', 5, 'hello, world')]
            # Delete two fields starting with second field
            [('#', 2, 2)]
        '''
        index_name = kwargs.get("index", 0)

        if isinstance(space_name, string_types):
            space_name = self.schema.get_space(space_name).sid
        if isinstance(index_name, string_types):
            index_name = self.schema.get_index(space_name, index_name).iid
        op_list = self._ops_process(space_name, op_list)
        request = RequestUpsert(self, space_name, index_name, tuple_value,
                                op_list)
        return self._send_request(request)