Esempio n. 1
0
    def update(self, space_name, key, op_list, **kwargs):
        '''
        Execute UPDATE request.
        Update single record identified by `key` (using primary index).

        List of operations allows to update individual fields.

        :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 key: key that identifies a record
        :type key: int or str
        :param op_list: list of operations. Each operation
            is tuple of three values
        :type op_list: a list of the form
            [(field_1, symbol_1, arg_1), (field_2, symbol_2, arg_2),...]

        :rtype: `Response` instance
        '''
        index_name = kwargs.get("index", 0)

        key = check_key(key)
        if isinstance(space_name, basestring):
            space_name = self.schema.get_space(space_name).sid
        if isinstance(index_name, basestring):
            index_name = self.schema.get_index(space_name, index_name).iid
        request = RequestUpdate(self, space_name, index_name, key, op_list)
        return self._send_request(request)
Esempio n. 2
0
    def update(self, space_name, key, op_list, **kwargs):
        index_name = kwargs.get("index", 0)

        key = check_key(key)
        if isinstance(space_name, str):
            sp = yield from self.schema.get_space(space_name)
            space_name = sp.sid

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

        res = yield from self._send_request(
            RequestUpdate(self, space_name, index_name, key, op_list))

        return res
Esempio n. 3
0
    def update(self, space_name, key, op_list, return_tuple=False):
        '''\
        Execute UPDATE request.
        Update single record identified by `key` (using primary index).

        List of operations allows to update individual fields.

        :param space_name: space number or name to update a record
        :type space_name: int or str
        :param key: key that identifies a record
        :type key: int or str
        :param op_list: list of operations. Each operation is tuple of three values
        :type op_list: a list of the form [(field_1, symbol_1, arg_1), (field_2, symbol_2, arg_2),...]
        :param return_tuple: indicates that it is required to return the updated tuple back
        :type return_tuple: bool

        :rtype: `Response` instance
        '''
        assert isinstance(key, (int, basestring))

        request = RequestUpdate(space_name, key, op_list, return_tuple)
        return self._send_request(request, space_name)
Esempio n. 4
0
 def pack(self, connection):
     return RequestUpdate(connection, self.space_no, 0, self.value_list, self.update_list)
Esempio n. 5
0
    "box.schema.user.grant('guest', 'read,write,execute', 'space', 'test_index_base')"
)

c = Connection('localhost', server.iproto.port)
c.connect()
s = c._socket

request = RequestInsert(c, 568, [1, 0, 0, 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)
Esempio n. 6
0
    "box.schema.user.grant('guest', 'read,write,execute', 'space', 'test_index_base')"
)

c = Connection("localhost", server.iproto.port)
c.connect()
s = c._socket

request = RequestInsert(c, 568, [1, 0, 0, 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)
Esempio n. 7
0
    def update(self, space_name, key, op_list, **kwargs):
        '''
        Execute UPDATE request.

        The `update` function supports operations on fields — assignment,
        arithmetic (if the field is unsigned numeric), cutting and pasting
        fragments of a field, deleting or inserting a field. Multiple
        operations can be combined in a single update request, and in this
        case they are performed atomically and sequentially. Each operation
        requires specification of a field number. When multiple operations are
        present, the field number for each operation is assumed to be relative
        to the most recent state of the tuple, that is, as if all previous
        operations in a multi-operation update have already been applied.
        In other words, it is always safe to merge multiple update invocations
        into a single invocation, with no change in semantics.

        Update single record identified by `key`.

        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 (before) (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 key: key that identifies a record
        :type key: int or str
        :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)

        key = check_key(key)
        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 = RequestUpdate(self, space_name, index_name, key, op_list)
        return self._send_request(request)