Ejemplo n.º 1
0
    def transaction(self, tx_type):
        """ Open a transaction to Grakn on this keyspace

        Can be used as `with session.transaction(grakn.TxType.READ) as tx: ...`
        Don't forget to commit within the `with`!
        Alternatively you can still do `tx = session.transaction(...); ...; tx.close()`

        :param grakn.TxType tx_type: The type of transaction to open as indicated by the tx_type enum
        """
        if self._closed:
            raise ClientError("Session is closed")

        # create a transaction service which hides GRPC usage
        transaction_service = TransactionService(self.keyspace, tx_type,
                                                 self.credentials,
                                                 self._stub.transaction)
        return Transaction(transaction_service)
Ejemplo n.º 2
0
 def write(self):
     transaction_service = TransactionService(
         self._session_id, _TxType.WRITE, self._transaction_rpc_constructor)
     return Transaction(transaction_service)
Ejemplo n.º 3
0
 def read(self):
     transaction_service = TransactionService(
         self._session_id, _TxType.READ, self._transaction_rpc_constructor)
     return Transaction(transaction_service)