Esempio n. 1
0
    def __init__(self,
                 channel: grpc.Channel,
                 session_id: str,
                 transaction_type: TransactionType,
                 options=GraknOptions()):
        self._transaction_type = transaction_type
        self._concept_manager = ConceptManager(self)
        self._query_manager = QueryManager(self)
        self._logic_manager = LogicManager(self)
        self._response_queues = {}

        self._grpc_stub = GraknStub(channel)
        self._request_iterator = RequestIterator()
        self._response_iterator = self._grpc_stub.transaction(
            self._request_iterator)
        self._transaction_was_closed = False

        open_req = transaction_proto.Transaction.Open.Req()
        open_req.session_id = session_id
        open_req.type = Transaction._transaction_type_proto(transaction_type)
        open_req.options.CopyFrom(grakn_proto_builder.options(options))
        req = transaction_proto.Transaction.Req()
        req.open_req.CopyFrom(open_req)

        start_time = time.time() * 1000.0
        res = self._execute(req)
        end_time = time.time() * 1000.0
        self._network_latency_millis = end_time - start_time - res.open_res.processing_time_millis
Esempio n. 2
0
    def __init__(self,
                 client,
                 database: str,
                 session_type: SessionType,
                 options=GraknOptions()):
        self._channel = client._channel
        self._scheduler = client._scheduler
        self._database = database
        self._session_type = session_type
        self._grpc_stub = GraknStub(self._channel)

        open_req = session_proto.Session.Open.Req()
        open_req.database = database
        open_req.type = Session._session_type_proto(session_type)
        open_req.options.CopyFrom(grakn_proto_builder.options(options))

        self._session_id = self._grpc_stub.session_open(open_req).session_id
        self._is_open = True
        self._pulse = self._scheduler.enter(5, 1, self._transmit_pulse, ())
Esempio n. 3
0
 def session(self,
             database: str,
             session_type: SessionType,
             options=GraknOptions()):
     return _Session(self, database, session_type, options)
Esempio n. 4
0
 def undefine(self, query: str, options=GraknOptions()):
     request = query_proto.Query.Req()
     undefine_req = query_proto.Graql.Undefine.Req()
     undefine_req.query = query
     request.undefine_req.CopyFrom(undefine_req)
     self._run_query(request, options)
Esempio n. 5
0
 def delete(self, query: str, options=GraknOptions()):
     request = query_proto.Query.Req()
     delete_req = query_proto.Graql.Delete.Req()
     delete_req.query = query
     request.delete_req.CopyFrom(delete_req)
     self._run_query(request, options)
Esempio n. 6
0
 def insert(self, query: str, options=GraknOptions()):
     request = query_proto.Query.Req()
     insert_req = query_proto.Graql.Insert.Req()
     insert_req.query = query
     request.insert_req.CopyFrom(insert_req)
     return map(lambda answer_proto: concept_map._of(answer_proto), self._iterate_query(request, lambda res: res.query_res.insert_res.answers, options))
Esempio n. 7
0
 def match(self, query: str, options=GraknOptions()):
     request = query_proto.Query.Req()
     match_req = query_proto.Graql.Match.Req()
     match_req.query = query
     request.match_req.CopyFrom(match_req)
     return map(lambda answer_proto: concept_map._of(answer_proto), self._iterate_query(request, lambda res: res.query_res.match_res.answers, options))
Esempio n. 8
0
 def transaction(self,
                 transaction_type: TransactionType,
                 options=GraknOptions()):
     return Transaction(self._channel, self._session_id, transaction_type,
                        options)