pub trait Connection: Send + Sync {
type Tx<'conn>: TransactionOps
where Self: 'conn;
Show 14 methods
// Required methods
fn query(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<Vec<Row>, Error>> + Send;
fn query_one(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<Option<Row>, Error>> + Send;
fn execute(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<u64, Error>> + Send;
fn insert(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<i64, Error>> + Send;
fn batch(
&self,
cx: &Cx,
statements: &[(String, Vec<Value>)],
) -> impl Future<Output = Outcome<Vec<u64>, Error>> + Send;
fn begin(
&self,
cx: &Cx,
) -> impl Future<Output = Outcome<Self::Tx<'_>, Error>> + Send;
fn begin_with(
&self,
cx: &Cx,
isolation: IsolationLevel,
) -> impl Future<Output = Outcome<Self::Tx<'_>, Error>> + Send;
fn prepare(
&self,
cx: &Cx,
sql: &str,
) -> impl Future<Output = Outcome<PreparedStatement, Error>> + Send;
fn query_prepared(
&self,
cx: &Cx,
stmt: &PreparedStatement,
params: &[Value],
) -> impl Future<Output = Outcome<Vec<Row>, Error>> + Send;
fn execute_prepared(
&self,
cx: &Cx,
stmt: &PreparedStatement,
params: &[Value],
) -> impl Future<Output = Outcome<u64, Error>> + Send;
fn ping(&self, cx: &Cx) -> impl Future<Output = Outcome<(), Error>> + Send;
fn close(self, cx: &Cx) -> impl Future<Output = Result<()>> + Send;
// Provided methods
fn dialect(&self) -> Dialect { ... }
fn is_valid(&self, cx: &Cx) -> impl Future<Output = bool> + Send { ... }
}Required Associated Types§
Sourcetype Tx<'conn>: TransactionOps
where
Self: 'conn
type Tx<'conn>: TransactionOps where Self: 'conn
The transaction type returned by this connection.
Required Methods§
Sourcefn query(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<Vec<Row>, Error>> + Send
fn query( &self, cx: &Cx, sql: &str, params: &[Value], ) -> impl Future<Output = Outcome<Vec<Row>, Error>> + Send
Execute a query and return all rows.
Sourcefn query_one(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<Option<Row>, Error>> + Send
fn query_one( &self, cx: &Cx, sql: &str, params: &[Value], ) -> impl Future<Output = Outcome<Option<Row>, Error>> + Send
Execute a query and return the first row, if any.
Sourcefn execute(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<u64, Error>> + Send
fn execute( &self, cx: &Cx, sql: &str, params: &[Value], ) -> impl Future<Output = Outcome<u64, Error>> + Send
Execute a statement (INSERT, UPDATE, DELETE) and return rows affected.
Sourcefn insert(
&self,
cx: &Cx,
sql: &str,
params: &[Value],
) -> impl Future<Output = Outcome<i64, Error>> + Send
fn insert( &self, cx: &Cx, sql: &str, params: &[Value], ) -> impl Future<Output = Outcome<i64, Error>> + Send
Execute an INSERT and return the last inserted ID.
For PostgreSQL, this typically uses RETURNING to get the inserted ID. The exact behavior depends on the driver implementation.
Sourcefn batch(
&self,
cx: &Cx,
statements: &[(String, Vec<Value>)],
) -> impl Future<Output = Outcome<Vec<u64>, Error>> + Send
fn batch( &self, cx: &Cx, statements: &[(String, Vec<Value>)], ) -> impl Future<Output = Outcome<Vec<u64>, Error>> + Send
Execute multiple statements in a batch.
Returns the number of rows affected by each statement. The statements are executed sequentially but may be optimized by the driver for better performance.
Sourcefn begin(
&self,
cx: &Cx,
) -> impl Future<Output = Outcome<Self::Tx<'_>, Error>> + Send
fn begin( &self, cx: &Cx, ) -> impl Future<Output = Outcome<Self::Tx<'_>, Error>> + Send
Begin a transaction with default isolation level (ReadCommitted).
Sourcefn begin_with(
&self,
cx: &Cx,
isolation: IsolationLevel,
) -> impl Future<Output = Outcome<Self::Tx<'_>, Error>> + Send
fn begin_with( &self, cx: &Cx, isolation: IsolationLevel, ) -> impl Future<Output = Outcome<Self::Tx<'_>, Error>> + Send
Begin a transaction with a specific isolation level.
Sourcefn prepare(
&self,
cx: &Cx,
sql: &str,
) -> impl Future<Output = Outcome<PreparedStatement, Error>> + Send
fn prepare( &self, cx: &Cx, sql: &str, ) -> impl Future<Output = Outcome<PreparedStatement, Error>> + Send
Prepare a statement for repeated execution.
Prepared statements are cached by the driver and can be executed multiple times with different parameters efficiently.
Sourcefn query_prepared(
&self,
cx: &Cx,
stmt: &PreparedStatement,
params: &[Value],
) -> impl Future<Output = Outcome<Vec<Row>, Error>> + Send
fn query_prepared( &self, cx: &Cx, stmt: &PreparedStatement, params: &[Value], ) -> impl Future<Output = Outcome<Vec<Row>, Error>> + Send
Execute a prepared statement and return all rows.
Sourcefn execute_prepared(
&self,
cx: &Cx,
stmt: &PreparedStatement,
params: &[Value],
) -> impl Future<Output = Outcome<u64, Error>> + Send
fn execute_prepared( &self, cx: &Cx, stmt: &PreparedStatement, params: &[Value], ) -> impl Future<Output = Outcome<u64, Error>> + Send
Execute a prepared statement (INSERT, UPDATE, DELETE) and return rows affected.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.