def mutate(self, setnquads=None, delnquads=None, *args, **kwargs): """Mutate extends MutateObj to allow mutations to be specified as N-Quad strings. Mutations also support a commit_now method which commits the transaction along with the mutation. This mode is presently unsupported. Params ====== * setnquads: a string containing nquads to set * delnquads: a string containing nquads to delete N-Quad format is <subj> <pred> <obj> . """ if self._finished: raise Exception('Transaction is complete') mutation = api.Mutation(start_ts=self.start_ts, commit_now=False) if kwargs.pop('ignore_index_conflict', None): mutation.ignore_index_conflict = True if setnquads: mutation.set_nquads = setnquads.encode('utf8') if delnquads: mutation.del_nquads = delnquads.encode('utf8') assigned = self.client.stub.Mutate(mutation, *args, **kwargs) self.merge_context(assigned.context) self._mutated = True return assigned
def delete_edge(edges: Dict[str, Any] = None): """ this will delete edge for given edges, node itself will not be deleted, edges should be given like this: edges = { "uid": "0xea8d", "madeOf": [ { "uid": "0xea8c" }, { "uid": "0xea8b" } ] } """ txn = client.txn() try: mutation = api.Mutation(delete_json=bytes(json.dumps(edges), encoding='utf-8')) future = txn.async_mutate(mutation=mutation, commit_now=True) response = pydgraph.Txn.handle_mutate_future(txn, future, True) finally: txn.discard() return response
def mutate_obj(self, setobj=None, delobj=None, *args, **kwargs): """Mutate allows modification of the data stored in the DGraph instance. A mutation can be described either using JSON or via RDF quads. This method presently support mutations described via JSON. Mutations also support a commit_now method which commits the transaction along with the mutation. This mode is presently unsupported. Params ====== * setobj: an object with data to set, to be encoded as JSON and converted to utf8 bytes * delobj: an object with data to be deleted, to be encoded as JSON and converted to utf8 bytes. """ if self._finished: raise Exception('Transaction is complete') mutation = api.Mutation(start_ts=self.start_ts, commit_now=False) if kwargs.pop('ignore_index_conflict', None): mutation.ignore_index_conflict = True if setobj: mutation.set_json = json.dumps(setobj).encode('utf8') if delobj: mutation.delete_json = json.dumps(delobj).encode('utf8') assigned = self.client.stub.Mutate(mutation, *args, **kwargs) self.merge_context(assigned.context) self._mutated = True return assigned
def _common_mutate(self, mutation=None, set_obj=None, del_obj=None, set_nquads=None, del_nquads=None, query=None, commit_now=None, ignore_index_conflict=None): if self._read_only: raise Exception( 'Readonly transaction cannot run mutations or be committed') if self._finished: raise Exception( 'Transaction has already been committed or discarded') if not mutation: mutation = api.Mutation() if set_obj: mutation.set_json = json.dumps(set_obj).encode('utf8') if del_obj: mutation.delete_json = json.dumps(del_obj).encode('utf8') if set_nquads: mutation.set_nquads = set_nquads.encode('utf8') if del_nquads: mutation.del_nquads = del_nquads.encode('utf8') if query: mutation.query = query.encode('utf8') if commit_now: mutation.commit_now = True if ignore_index_conflict: mutation.ignore_index_conflict = True self._mutated = True mutation.start_ts = self._ctx.start_ts return mutation
def _common_mutate(self, mu=None, set_obj=None, del_obj=None, set_nquads=None, del_nquads=None, commit_now=None, ignore_index_conflict=None): if not mu: mu = api.Mutation() if set_obj: mu.set_json = json.dumps(set_obj).encode('utf8') if del_obj: mu.delete_json = json.dumps(del_obj).encode('utf8') if set_nquads: mu.set_nquads = set_nquads.encode('utf8') if del_nquads: mu.del_nquads = del_nquads.encode('utf8') if commit_now: mu.commit_now = True if ignore_index_conflict: mu.ignore_index_conflict = True if self._finished: raise Exception( 'Transaction has already been committed or discarded') self._mutated = True mu.start_ts = self._ctx.start_ts return mu
async def amutate_obj(self, setobj=None, delobj=None, *args, **kwargs): if self._finished: raise Exception('Transaction is complete') mutation = api.Mutation(start_ts=self.start_ts, commit_now=False) if kwargs.pop('ignore_index_conflict', None): mutation.ignore_index_conflict = True if setobj: mutation.set_json = json.dumps(setobj).encode('utf8') if delobj: mutation.del_json = json.dumps(delobj).encode('utf8'), assigned = await self.client.stub.Mutate.future( mutation, *args, **kwargs) self.merge_context(assinged.context) self._mutated = True return assigned
def create_mutation(self, mutation=None, set_obj=None, del_obj=None, set_nquads=None, del_nquads=None, cond=None): if not mutation: mutation = api.Mutation() if set_obj: mutation.set_json = json.dumps(set_obj).encode('utf8') if del_obj: mutation.delete_json = json.dumps(del_obj).encode('utf8') if set_nquads: mutation.set_nquads = set_nquads.encode('utf8') if del_nquads: mutation.del_nquads = del_nquads.encode('utf8') if cond: mutation.cond = cond.encode('utf8') return mutation