Ejemplo n.º 1
0
    async def get_one(self, table, filter={}, id=0):

        if self._connection:
            try:
                self._result = (
                    await self._engine.table(table)
                    .filter(filter)
                    .nth(id)
                    .run(self._connection)
                )
                return self._result
            except ReqlNonExistenceError as err:
                raise ReqlNonExistenceError("Empty Result: {}".format(str(err)))
            except ReqlRuntimeError as err:
                raise ReqlRuntimeError(str(err))
            except Exception as err:
                raise Exception(err)
Ejemplo n.º 2
0
 async def _run_query(self, query, noreply, raise_for_errors=True):
     query_noreply = 'noreply ' if noreply else ''
     logger.debug(f'Send {query_noreply}query {query}')
     await self._socket.send_query(query)
     if noreply:
         return None
     res = await self._socket.read_response(query)
     logger.debug(f'Receive response {res}')
     if res.type == ResponseType.SUCCESS_ATOM:
         data = res.data[0]
         if raise_for_errors and query.is_writing():
             if data.get('errors'):
                 raise ReqlProgrammingError(data, query.term)
         return maybe_profile(data, res)
     elif res.type in {
             ResponseType.SUCCESS_PARTIAL, ResponseType.SUCCESS_SEQUENCE
     }:
         if query.type == QueryType.CONTINUE:
             return res
         else:
             return CurioCursor(self, query, res)
     elif res.type == ResponseType.WAIT_COMPLETE:
         return None
     elif res.type == ResponseType.SERVER_INFO:
         return res.data[0]
     else:
         error = (res.data[0], query.term, res.backtrace)
         if res.type == ResponseType.CLIENT_ERROR:
             raise ReqlDriverError(*error)
         elif res.type == ResponseType.COMPILE_ERROR:
             raise ReqlServerCompileError(*error)
         elif res.type == ResponseType.RUNTIME_ERROR:
             raise ReqlRuntimeError(*error)
         else:
             raise ReqlDriverError(
                 f'Unknown Response type {res.type} encountered.')
Ejemplo n.º 3
0
 def _error(self, message):
     # Set an error and extend with a dummy response to trigger any waiters
     if self.error is None:
         self.error = ReqlRuntimeError(message, self.query.term, [])
         dummy_response = '{"t":%d,"r":[]}' % pResponse.SUCCESS_SEQUENCE
         self._extend(dummy_response)