pub trait Connection: Send + Sync {
Show 14 methods
// Required methods
fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Transaction + '_>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn PreparedStatement + '_>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn tables<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn columns<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ColumnInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn indexes<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<IndexInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn foreign_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ForeignKeyInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn execute_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait { ... }
fn query_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait { ... }
fn last_warnings(&self) -> Vec<SqlWarning> { ... }
fn query_stream<'a>(
&'a self,
sql: &'a str,
params: &'a [&'a dyn ToSqlValue],
) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>> { ... }
}Expand description
An async database connection.
Implementations must be Send + Sync so they can be shared across async
tasks. Use transaction to obtain a transaction
that provides serialised, rollbackable execution.
Required Methods§
Sourcefn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Execute a DML/DDL statement and return the number of rows affected.
Positional parameters ($1, $2, …) are substituted from params.
Sourcefn query<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Execute a SELECT statement and return the result rows.
Positional parameters ($1, $2, …) are substituted from params.
Sourcefn transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Transaction + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Transaction + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Begin a transaction, returning a handle that can be committed or rolled back.
Provided Methods§
Sourcefn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute multiple semicolon-separated SQL statements in a single call.
The default implementation splits on ; and calls execute
for each statement. Backends may override with a more efficient
batch execution path (e.g. batch_execute on Postgres).
Note: The default implementation uses a naive ; split and will
break on SQL containing semicolons inside string literals. Backends
that override this method (Postgres, MySQL, embedded) handle this
correctly via their native batch execution APIs.
Returns the total number of rows affected across all statements.
Sourcefn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lightweight connectivity check.
The default implementation executes SELECT 1 and discards the result.
Backends should override with a more efficient probe if available.
Sourcefn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn PreparedStatement + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn PreparedStatement + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Compile a SQL statement for repeated execution with different parameters.
Returns a PreparedStatement that avoids re-parsing on each call.
The default implementation returns an error indicating the backend does
not support prepared statements; override in backend-specific impls.
Sourcefn tables<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn tables<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List all tables visible to the current connection.
The default implementation returns an unsupported error. Backends that support introspection (Postgres, MySQL, embedded) override this.
Sourcefn columns<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ColumnInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn columns<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ColumnInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
List all columns of the named table.
The default implementation returns an unsupported error.
Sourcefn indexes<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<IndexInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn indexes<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<IndexInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
List all indexes defined on the named table.
The default implementation returns an unsupported error.
Sourcefn foreign_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ForeignKeyInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn foreign_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ForeignKeyInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
List all foreign-key constraints on the named table.
The default implementation returns an unsupported error.
Sourcefn execute_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn execute_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Execute a SQL statement with named parameters.
Placeholders :name, $name, and @name are translated to positional
form and forwarded to execute.
§Errors
Returns OxiSqlError::Params if a named placeholder has no corresponding
entry in params, or any error from the underlying execute call.
Sourcefn query_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn query_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Execute a SQL query with named parameters and return the result rows.
Placeholders :name, $name, and @name are translated to positional
form and forwarded to query.
See execute_named for placeholder syntax.
§Errors
Returns OxiSqlError::Params if a named placeholder has no corresponding
entry in params, or any error from the underlying query call.
Sourcefn last_warnings(&self) -> Vec<SqlWarning>
fn last_warnings(&self) -> Vec<SqlWarning>
Return any SQL warnings generated by the most recently executed statement.
The list is cleared before each execute or query call and repopulated
afterwards with warnings issued by the server (if any). Backends that do
not support warning retrieval return an empty Vec (the default).
MySQL warnings are fetched via SHOW WARNINGS — only when the server
reports warnings_count > 0 in the OkPacket, so there is no extra
round-trip on the common no-warning path.
§Example
conn.execute("INSERT INTO t (col) VALUES (?)", &[&"too long value"]).await.unwrap();
for w in conn.last_warnings() {
eprintln!("Warning {}: {}", w.code, w.message);
}Sourcefn query_stream<'a>(
&'a self,
sql: &'a str,
params: &'a [&'a dyn ToSqlValue],
) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>
fn query_stream<'a>( &'a self, sql: &'a str, params: &'a [&'a dyn ToSqlValue], ) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>
Execute a SELECT and return rows as an async stream.
The default implementation materialises the full result via query
then streams the rows. Backends that support true server-side cursors may
override with incremental fetching.
This is a regular (non-async) method that returns Pin<Box<dyn Stream>> directly.
The default body wraps the future returned by query in a
one-shot stream and flattens the result into per-row items.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".