def _select(self, space_name, index_name, values, offset=0, limit=0xffffffff): '''\ Low level version of select() method. :param space_name: space number of name to select data :type space_name: int or str :param index_name: index id to use :type index_name: int or str :param values: list of values to search over the index :type values: list of tuples :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 ''' # 'values' argument must be a list of tuples assert isinstance(values, (list, tuple)) assert len(values) != 0 assert isinstance(values[0], (list, tuple)) request = RequestSelect(self, space_name, index_name, values, offset, limit) response = self._send_request(request, space_name) 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 select(conn, space_no, index_no, key, offset=0, limit=0, iterator=0): data = RequestSelect(conn, space_no, index_no, key, offset, limit, iterator) response = conn._send_request(data) if response.return_code: return format_error(response) return format_yamllike(response)
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
c = Connection('localhost', server.iproto.port) c.connect() request1 = RequestInsert(c, 567, [1, "baobab"]) request2 = RequestInsert(c, 567, [2, "obbaba"]) s = c._socket try: s.send(bytes(request1) + bytes(request2)) except OSError as e: print ' => ', 'Failed to send request' response1 = Response(c, c._read_response()) response2 = Response(c, c._read_response()) print response1.__str__() print response2.__str__() request1 = RequestInsert(c, 567, [3, "occama"]) request2 = RequestSelect(c, 567, 0, [1], 0, 1, 0) s = c._socket try: s.send(bytes(request1) + bytes(request2)) except OSError as e: print ' => ', 'Failed to send request' response1 = Response(c, c._read_response()) response2 = Response(c, c._read_response()) print response1.__str__() print response2.__str__() request1 = RequestSelect(c, 567, 0, [2], 0, 1, 0) request2 = RequestInsert(c, 567, [4, "ockham"]) s = c._socket try: s.send(bytes(request1) + bytes(request2))
def pack(self, connection): return RequestSelect(connection, self.space_no, self.index_no, self.key, self.offset, self.limit, self.iterator)