pub struct AsyncConnectionBuilder { /* private fields */ }Expand description
An async builder for creating database connections.
See ConnectionBuilder for the sync
equivalent and the full contract. All setters are identical; only
the terminal build() calls are async.
§Example
use hyperdb_api::{AsyncConnectionBuilder, CreateMode, Result};
#[tokio::main]
async fn main() -> Result<()> {
let conn = AsyncConnectionBuilder::new("localhost:7483")
.database("example.hyper")
.create_mode(CreateMode::CreateIfNotExists)
.auth("myuser", "mypassword")
.build()
.await?;
Ok(())
}Implementations§
Source§impl AsyncConnectionBuilder
impl AsyncConnectionBuilder
Sourcepub fn create_mode(self, mode: CreateMode) -> Self
pub fn create_mode(self, mode: CreateMode) -> Self
Sets the database creation mode.
Sourcepub fn password(self, password: impl Into<String>) -> Self
pub fn password(self, password: impl Into<String>) -> Self
Sets the password for authentication.
Sourcepub fn login_timeout(self, timeout: Duration) -> Self
pub fn login_timeout(self, timeout: Duration) -> Self
Sets the login timeout.
Sourcepub fn query_timeout(self, timeout: Duration) -> Self
pub fn query_timeout(self, timeout: Duration) -> Self
Sets the query timeout.
Sourcepub fn application_name(self, name: impl Into<String>) -> Self
pub fn application_name(self, name: impl Into<String>) -> Self
Sets the application name sent to the server.
Sourcepub fn auth(self, user: impl Into<String>, password: impl Into<String>) -> Self
pub fn auth(self, user: impl Into<String>, password: impl Into<String>) -> Self
Convenience method to set user and password at once.
Sourcepub fn create_new_database(self, database_path: impl AsRef<Path>) -> Self
pub fn create_new_database(self, database_path: impl AsRef<Path>) -> Self
Convenience method to create a new database.
Sourcepub fn create_or_open_database(self, database_path: impl AsRef<Path>) -> Self
pub fn create_or_open_database(self, database_path: impl AsRef<Path>) -> Self
Convenience method to create database if it doesn’t exist.
Sourcepub fn open_database(self, database_path: impl AsRef<Path>) -> Self
pub fn open_database(self, database_path: impl AsRef<Path>) -> Self
Convenience method to open an existing database.
Sourcepub fn transfer_mode(self, mode: TransferMode) -> Self
pub fn transfer_mode(self, mode: TransferMode) -> Self
Sets the transfer mode for gRPC connections (ignored for TCP).
Sourcepub async fn build(self) -> Result<AsyncConnection>
pub async fn build(self) -> Result<AsyncConnection>
Builds and establishes the connection (async).
Transport is auto-detected from the endpoint URL:
https:///http://→ gRPCtab.domain://→ Unix domain socket (Unix only)tab.pipe://→ named pipe (Windows only)- otherwise → TCP
§Errors
- Returns
Error::IoorError::Clientif the transport handshake fails (TCP refused, TLS rejected, named-pipe not found, gRPC channel setup failure). - Returns
Error::Clientif authentication is rejected. - Returns
Error::Clientif theCreateModeSQL is rejected for a builder that configured a database path.
Trait Implementations§
Source§impl Clone for AsyncConnectionBuilder
impl Clone for AsyncConnectionBuilder
Source§fn clone(&self) -> AsyncConnectionBuilder
fn clone(&self) -> AsyncConnectionBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AsyncConnectionBuilder
impl Debug for AsyncConnectionBuilder
Auto Trait Implementations§
impl Freeze for AsyncConnectionBuilder
impl RefUnwindSafe for AsyncConnectionBuilder
impl Send for AsyncConnectionBuilder
impl Sync for AsyncConnectionBuilder
impl Unpin for AsyncConnectionBuilder
impl UnsafeUnpin for AsyncConnectionBuilder
impl UnwindSafe for AsyncConnectionBuilder
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Wrap the input message
T in a tonic::Request