Struct typedb_driver::Session
source · pub struct Session { /* private fields */ }
Expand description
A session with a TypeDB database.
Implementations§
source§impl Session
impl Session
sourcepub async fn new(database: Database, session_type: SessionType) -> Result<Self>
pub async fn new(database: Database, session_type: SessionType) -> Result<Self>
Opens a communication tunnel (session) to the given database with default options.
See Session::new_with_options
sourcepub async fn new_with_options(
database: Database,
session_type: SessionType,
options: Options
) -> Result<Self>
pub async fn new_with_options( database: Database, session_type: SessionType, options: Options ) -> Result<Self>
Opens a communication tunnel (session) to the given database on the running TypeDB server.
§Arguments
database
– The database with which the session connectssession_type
– The type of session to be created (DATA or SCHEMA)options
–TypeDBOptions
for the session
§Examples
Session::new_with_options(database, session_type, options).await;
sourcepub fn database_name(&self) -> &str
pub fn database_name(&self) -> &str
sourcepub fn type_(&self) -> SessionType
pub fn type_(&self) -> SessionType
The current session’s type (SCHEMA or DATA)
sourcepub fn force_close(&self) -> Result
pub fn force_close(&self) -> Result
Closes the session. Before opening a new session, the session currently open should first be closed.
§Examples
session.force_close();
sourcepub fn on_reopen(&self, callback: impl FnMut() + Send + 'static)
pub fn on_reopen(&self, callback: impl FnMut() + Send + 'static)
Registers a callback function which will be executed when this session is reopened. A session may be closed if it times out, or loses the connection to the database. In such situations, the session is reopened automatically when opening a new transaction.
§Arguments
function
– The callback function.
§Examples
session.on_reopen(function);
sourcepub async fn transaction(
&self,
transaction_type: TransactionType
) -> Result<Transaction<'_>>
pub async fn transaction( &self, transaction_type: TransactionType ) -> Result<Transaction<'_>>
Opens a transaction to perform read or write queries on the database connected to the session.
See Session::transaction_with_options
sourcepub async fn transaction_with_options(
&self,
transaction_type: TransactionType,
options: Options
) -> Result<Transaction<'_>>
pub async fn transaction_with_options( &self, transaction_type: TransactionType, options: Options ) -> Result<Transaction<'_>>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request