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, str): space_name = self.schema.get_space(space_name).sid if isinstance(index_name, str): 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)
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)
def select(self, space_name, key=None, **kwargs): ''' Execute SELECT request. Select and retrieve data from the database. :param space_name: specifies which space to query :type space_name: int or str :param values: values to search over the index :type values: list, tuple, set, frozenset of tuples :param index: specifies which index to use (default is **0** which means that the **primary index** will be used) :type index: int or str :param offset: offset in the resulting tuple set :type offset: int :param limit: limits the total number of returned tuples :type limit: int :rtype: `Response` instance You may use names for index/space. Matching id's -> names connector will get from server. Select one single record (from space=0 and using index=0) >>> select(0, 1) Select single record from space=0 (with name='space') using composite index=1 (with name '_name'). >>> select(0, [1,'2'], index=1) # OR >>> select(0, [1,'2'], index='_name') # OR >>> select('space', [1,'2'], index='_name') # OR >>> select('space', [1,'2'], index=1) Select all records >>> select(0) # OR >>> select(0, []) ''' # Initialize arguments and its defaults from **kwargs offset = kwargs.get("offset", 0) limit = kwargs.get("limit", 0xffffffff) index_name = kwargs.get("index", 0) iterator_type = kwargs.get("iterator", 0) # Perform smart type checking (scalar / list of scalars / list of # tuples) key = check_key(key, select=True) if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid if isinstance(index_name, str): index_name = self.schema.get_index(space_name, index_name).iid request = RequestSelect(self, space_name, index_name, key, offset, limit, iterator_type) response = self._send_request(request) return response
def select(self, space_name, key=None, **kwargs): ''' Execute SELECT request. Select and retrieve data from the database. :param space_name: specifies which space to query :type space_name: int or str :param values: values to search over the index :type values: list, tuple, set, frozenset of tuples :param index: specifies which index to use (default is **0** which means that the **primary index** will be used) :type index: int or str :param offset: offset in the resulting tuple set :type offset: int :param limit: limits the total number of returned tuples :type limit: int :rtype: `Response` instance You may use names for index/space. Matching id's -> names connector will get from server. Select one single record (from space=0 and using index=0) >>> select(0, 1) Select single record from space=0 (with name='space') using composite index=1 (with name '_name'). >>> select(0, [1,'2'], index=1) # OR >>> select(0, [1,'2'], index='_name') # OR >>> select('space', [1,'2'], index='_name') # OR >>> select('space', [1,'2'], index=1) Select all records >>> select(0) # OR >>> select(0, []) ''' # Initialize arguments and its defaults from **kwargs offset = kwargs.get("offset", 0) limit = kwargs.get("limit", 0xffffffff) index_name = kwargs.get("index", 0) iterator_type = kwargs.get("iterator", 0) # Perform smart type checking (scalar / list of scalars / list of # tuples) key = check_key(key, select=True) 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 = RequestSelect(self, space_name, index_name, key, offset, limit, iterator_type) response = self._send_request(request) return response
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
async def delete(self, space_name, key, **kwargs): index_name = kwargs.get("index", 0) key = check_key(key) 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( RequestDelete(self, space_name, index_name, key)) return res
def select(self, space_name, key=None, **kwargs): offset = kwargs.get("offset", 0) limit = kwargs.get("limit", 0xffffffff) index_name = kwargs.get("index", 0) iterator_type = kwargs.get("iterator", 0) key = check_key(key, select=True) 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( RequestSelect(self, space_name, index_name, key, offset, limit, iterator_type)) return res
def delete(self, space_name, key, **kwargs): ''' Execute DELETE request. Delete single record identified by `key` (using primary index). :param space_name: space number or name to delete a record :type space_name: int or name :param key: key that identifies a record :type key: int or str :rtype: `Response` instance ''' index_name = kwargs.get("index", 0) key = check_key(key) if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid if isinstance(index_name, str): index_name = self.schema.get_index(space_name, index_name).iid request = RequestDelete(self, space_name, index_name, key) return self._send_request(request)
def delete(self, space_name, key, **kwargs): ''' Execute DELETE request. Delete single record identified by `key` (using primary index). :param space_name: space number or name to delete a record :type space_name: int or name :param key: key that identifies a record :type key: int or str :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 = RequestDelete(self, space_name, index_name, key) return self._send_request(request)
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)
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, six.string_types): space_name = self.schema.get_space(space_name).sid if isinstance(index_name, six.string_types): 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)