Ejemplo n.º 1
0
 def undefine(self,
              query: str,
              options: TypeDBOptions = None) -> QueryFuture:
     if not options:
         options = TypeDBOptions.core()
     return self.query_void(
         query_manager_undefine_req(query, options.proto()))
Ejemplo n.º 2
0
 def insert(self,
            query: str,
            options: TypeDBOptions = None) -> Iterator[ConceptMap]:
     if not options:
         options = TypeDBOptions.core()
     return (_ConceptMap.of(cm) for rp in self.stream(
         query_manager_insert_req(query, options.proto()))
             for cm in rp.insert_res_part.answers)
Ejemplo n.º 3
0
 def match_aggregate(self,
                     query: str,
                     options: TypeDBOptions = None) -> QueryFuture[Numeric]:
     if not options:
         options = TypeDBOptions.core()
     return self.query(
         query_manager_match_aggregate_req(query, options.proto())).map(
             lambda res: _Numeric.of(res.match_aggregate_res.answer))
Ejemplo n.º 4
0
 def match_group_aggregate(
         self,
         query: str,
         options: TypeDBOptions = None) -> Iterator[NumericGroup]:
     if not options:
         options = TypeDBOptions.core()
     return (_NumericGroup.of(ng) for rp in self.stream(
         query_manager_match_group_aggregate_req(query, options.proto()))
             for ng in rp.match_group_aggregate_res_part.answers)
Ejemplo n.º 5
0
 def match_group(
         self,
         query: str,
         options: TypeDBOptions = None) -> Iterator[ConceptMapGroup]:
     if not options:
         options = TypeDBOptions.core()
     return (_ConceptMapGroup.of(cmg) for rp in self.stream(
         query_manager_match_group_req(query, options.proto()))
             for cmg in rp.match_group_res_part.answers)
Ejemplo n.º 6
0
 def explain(self,
             explainable: ConceptMap.Explainable,
             options: TypeDBOptions = None) -> Iterator[Explanation]:
     if not options:
         options = TypeDBOptions.core()
     return (_Explanation.of(ex) for rp in self.stream(
         query_manager_explain_req(explainable.explainable_id(),
                                   options.proto()))
             for ex in rp.explain_res_part.explanations)
Ejemplo n.º 7
0
 def transaction(self,
                 transaction_type: TransactionType,
                 options: TypeDBOptions = None) -> TypeDBTransaction:
     if not options:
         options = TypeDBOptions.core()
     try:
         self._rw_lock.acquire_read()
         return _TypeDBTransactionImpl(self, transaction_type, options)
     finally:
         self._rw_lock.release_read()
Ejemplo n.º 8
0
 def session(self,
             database: str,
             session_type: SessionType,
             options=None) -> _TypeDBSessionImpl:
     if not options:
         options = TypeDBOptions.core()
     session = _TypeDBSessionImpl(self, database, session_type, options)
     with self._sessions_lock:
         self._sessions[session.session_id()] = session
     return session
Ejemplo n.º 9
0
 def transaction(
         self,
         transaction_type: TransactionType,
         options: TypeDBClusterOptions = None) -> _TypeDBTransactionImpl:
     if not options:
         options = TypeDBOptions.cluster()
     return self._transaction_any_replica(
         transaction_type, options) if getattr(
             options, "read_any_replica",
             False) else self._transaction_primary_replica(
                 transaction_type, options)
Ejemplo n.º 10
0
 def session(self,
             database: str,
             session_type: SessionType,
             options=None) -> _ClusterSession:
     if not options:
         options = TypeDBOptions.cluster()
     return self._session_any_replica(
         database, session_type, options) if getattr(
             options, "read_any_replica",
             False) else self._session_primary_replica(
                 database, session_type, options)
Ejemplo n.º 11
0
    def __init__(self,
                 client: "_TypeDBClientImpl",
                 database: str,
                 session_type: SessionType,
                 options: TypeDBOptions = None):
        if not options:
            options = TypeDBOptions.core()
        self._client = client
        self._address = client.address()
        self._session_type = session_type
        self._options = options
        self._rw_lock = ReadWriteLock()
        self._database = _TypeDBDatabaseImpl(stub=self._stub(), name=database)

        start_time = time.time() * 1000.0
        res = self._stub().session_open(
            session_open_req(database, session_type.proto(), options.proto()))
        end_time = time.time() * 1000.0
        self._network_latency_millis = int(end_time - start_time -
                                           res.server_duration_millis)
        self._session_id = res.session_id
        self._is_open = AtomicBoolean(True)
Ejemplo n.º 12
0
    def __init__(self,
                 session: "_TypeDBSessionImpl",
                 transaction_type: TransactionType,
                 options: TypeDBOptions = None):
        if not options:
            options = TypeDBOptions.core()
        self._transaction_type = transaction_type
        self._options = options
        self._concept_manager = _ConceptManager(self)
        self._query_manager = _QueryManager(self)
        self._logic_manager = _LogicManager(self)

        try:
            self._channel, stub = session.client().new_channel_and_stub()
            self._bidirectional_stream = BidirectionalStream(
                stub, session.transmitter())
            req = transaction_open_req(session.session_id(),
                                       transaction_type.proto(),
                                       options.proto(),
                                       session.network_latency_millis())
            self.execute(request=req, batch=False)
        except RpcError as e:
            raise TypeDBClientException.of_rpc(e)