def create_request(self, query=None, variables=None, mutations=None, commit_now=None, resp_format="JSON"): if resp_format == "JSON": resp_format = api.Request.RespFormat.JSON elif resp_format == "RDF": resp_format = api.Request.RespFormat.RDF else: raise errors.TransactionError( 'Response format should be either RDF or JSON') """Creates a request object""" request = api.Request(start_ts=self._ctx.start_ts, commit_now=commit_now, read_only=self._read_only, best_effort=self._best_effort, resp_format=resp_format) if variables is not None: for key, value in variables.items(): if util.is_string(key) and util.is_string(value): request.vars[key] = value else: raise errors.TransactionError( 'Values and keys in variable map must be strings') if query: request.query = query.encode('utf8') if mutations: request.mutations.extend(mutations) return request
def query(self, q, *args, **kwargs): if self._finished: raise Exception('Transaction is complete') request = api.Request(query=q, start_ts=self.start_ts, lin_read=self.lin_read) response = self.client.stub.Query(request, *args, **kwargs) self.merge_context(response.txn) return response
def _common_query(self, query, variables=None): if self._finished: raise Exception( 'Transaction has already been committed or discarded') req = api.Request(query=query, start_ts=self._ctx.start_ts, read_only=self._read_only) if variables is not None: for key, value in variables.items(): if util.is_string(key) and util.is_string(value): req.vars[key] = value return req
def create_request(self, query=None, variables=None, mutations=None, commit_now=None): """Creates a request object""" request = api.Request(start_ts = self._ctx.start_ts, commit_now=commit_now, read_only=self._read_only, best_effort=self._best_effort) if variables is not None: for key, value in variables.items(): if util.is_string(key) and util.is_string(value): request.vars[key] = value else: raise Exception('Values and keys in variable map must be strings') if query: request.query = query.encode('utf8') if mutations: request.mutations.extend(mutations) return request
async def aquery(self, q, timeout=None): request = api.Request(query=q, lin_read=self.lin_read) response = await self.stub.Query.future(request, timeout) self.merge_context(response.txn) return response