pub struct AsyncConnection { /* private fields */ }Expand description
An async facade over a Connection.
Every method dispatches to tokio::task::spawn_blocking, so the connection
never blocks the async executor. The handle is cheap to clone; clones share
one connection, serialized by an internal mutex.
§Panics
These methods panic if called outside a Tokio runtime context, matching
tokio::task::spawn_blocking.
Implementations§
Source§impl AsyncConnection
impl AsyncConnection
Sourcepub fn new(conn: Connection) -> AsyncConnection
pub fn new(conn: Connection) -> AsyncConnection
Wraps an existing Connection for async use.
Sourcepub fn try_into_inner(self) -> Result<Connection, AsyncConnection>
pub fn try_into_inner(self) -> Result<Connection, AsyncConnection>
Recovers the inner Connection if this is the last handle.
Returns self unchanged (as Err) if other clones of this handle exist.
Sourcepub async fn open<P>(path: P) -> Result<AsyncConnection>
pub async fn open<P>(path: P) -> Result<AsyncConnection>
Opens a connection to a DuckDB database at the given file path.
§Errors
Returns an error if the database cannot be opened.
Sourcepub async fn open_in_memory() -> Result<AsyncConnection>
pub async fn open_in_memory() -> Result<AsyncConnection>
Opens an in-memory DuckDB connection.
§Errors
Returns an error if the connection cannot be established.
Sourcepub async fn with_connection<F, T>(&self, f: F) -> Result<T>
pub async fn with_connection<F, T>(&self, f: F) -> Result<T>
Runs an arbitrary closure against the connection on a blocking thread.
This is the primitive every other method on this type is built from. Use it directly for transactions and anything the typed helpers don’t cover.
§Errors
Returns an error if the closure returns one, or if the background task panics or is cancelled.
Sourcepub async fn execute_batch<S>(&self, sql: S) -> Result<()>
pub async fn execute_batch<S>(&self, sql: S) -> Result<()>
Executes one or more SQL statements separated by semicolons.
§Errors
Returns an error if any statement fails to execute.
Sourcepub async fn execute<S>(&self, sql: S) -> Result<ResultSet>
pub async fn execute<S>(&self, sql: S) -> Result<ResultSet>
Prepares and executes a SQL statement, materializing the result.
§Errors
Returns an error if DuckDB cannot prepare or execute the statement.
Sourcepub async fn execute_with<S>(
&self,
sql: S,
binds: Vec<DuckValue>,
) -> Result<ResultSet>
pub async fn execute_with<S>( &self, sql: S, binds: Vec<DuckValue>, ) -> Result<ResultSet>
Prepares and executes a parameterized SQL statement, materializing the result.
§Errors
Returns an error if preparation, binding, or execution fails.
Sourcepub async fn with_appender<F, T>(
&self,
table: impl Into<String> + Send,
schema: impl Into<String> + Send,
f: F,
) -> Result<T>
pub async fn with_appender<F, T>( &self, table: impl Into<String> + Send, schema: impl Into<String> + Send, f: F, ) -> Result<T>
Runs a closure against a bulk-insert Appender for table/schema on a
blocking thread.
The appender never leaves the closure — it holds raw FFI pointers, so it cannot be exposed as a standalone async handle.
§Errors
Returns an error if the table does not exist, the appender cannot be created, or the closure returns an error.
Trait Implementations§
Source§impl Clone for AsyncConnection
impl Clone for AsyncConnection
Source§fn clone(&self) -> AsyncConnection
fn clone(&self) -> AsyncConnection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more