sqlx/sqlx-core/src/connection.rs
Ryan Leckey 769e8aa461
refactor: introduce io::Stream (blocking::io::Stream) to encapsulate needed IO methods
- rename sqlx::AsyncRuntime to sqlx::Async
 - don't set default runtime in traits
2021-01-10 10:45:29 -08:00

34 lines
1.2 KiB
Rust

#[cfg(feature = "async")]
use futures_util::future::BoxFuture;
use crate::{Close, Connect, Database, Runtime};
/// A unique connection (session) with a specific database.
///
/// With a client/server model, this is equivalent to a network connection
/// to the server.
///
/// SQL statements will be executed and results returned within the context
/// of this single SQL connection.
///
// for<'a> &'a mut Rt::TcpStream: crate::io::Stream<'a>,
pub trait Connection<Rt>: 'static + Send + Connect<Rt> + Close<Rt>
where
Rt: Runtime,
{
type Database: Database<Rt, Connection = Self>;
/// Checks if a connection to the database is still valid.
///
/// The method of operation greatly depends on the database driver. In MySQL, there is an
/// explicit [`COM_PING`](https://dev.mysql.com/doc/internals/en/com-ping.html) command. In
/// PostgreSQL, `ping` will issue a query consisting of a comment `/* SQLx ping */` which,
/// in effect, does nothing apart from getting a response from the server.
///
#[cfg(feature = "async")]
fn ping(&mut self) -> BoxFuture<'_, crate::Result<()>>
where
Rt: crate::Async,
for<'s> <Rt as Runtime>::TcpStream: crate::io::Stream<'s, Rt>;
}