Struct tokio_postgres::Connection
[−]
[src]
pub struct Connection(_);
A connection to a Postgres database.
Methods
impl Connection
[src]
fn connect<T>(
params: T,
tls_mode: TlsMode,
handle: &Handle
) -> BoxFuture<Connection, ConnectError> where
T: IntoConnectParams,
params: T,
tls_mode: TlsMode,
handle: &Handle
) -> BoxFuture<Connection, ConnectError> where
T: IntoConnectParams,
Creates a new connection to a Postgres database.
Most applications can use a URL string in the normal format:
postgresql://user[:password]@host[:port][/database][?param1=val1[[¶m2=val2]...]]
The password may be omitted if not required. The default Postgres port (5432) is used if none is specified. The database name defaults to the username if not specified.
To connect to the server via Unix sockets, host
should be set to the
absolute path of the directory containing the socket file. Since /
is
a reserved character in URLs, the path should be URL encoded. If the
path contains non-UTF 8 characters, a ConnectParams
struct should be
created manually and passed in. Note that Postgres does not support TLS
over Unix sockets.
fn batch_execute(self, query: &str) -> BoxFuture<Connection, Error>
Execute a sequence of SQL statements.
Statements should be separated by ;
characters. If an error occurs,
execution of the sequence will stop at that point. This is intended for
execution of batches of non-dynamic statements - for example, creation
of a schema for a fresh database.
Warning
Prepared statements should be used for any SQL statement which contains user-specified data, as it provides functionality to safely embed that data in the statement. Do not form statements via string concatenation and feed them into this method.
fn prepare(self, query: &str) -> BoxFuture<(Statement, Connection), Error>
Creates a new prepared statement.
fn execute(
self,
statement: &Statement,
params: &[&ToSql]
) -> BoxFuture<(u64, Connection), Error>
self,
statement: &Statement,
params: &[&ToSql]
) -> BoxFuture<(u64, Connection), Error>
Executes a statement, returning the number of rows modified.
Panics
Panics if the number of parameters provided does not match the number expected.
fn query(
self,
statement: &Statement,
params: &[&ToSql]
) -> BoxStateStream<Row, Connection, Error>
self,
statement: &Statement,
params: &[&ToSql]
) -> BoxStateStream<Row, Connection, Error>
Executes a statement, returning a stream over the resulting rows.
Panics
Panics if the number of parameters provided does not match the number expected.
fn transaction(self) -> BoxFuture<Transaction, Error>
Starts a new transaction.
fn notifications(self) -> Notifications
Returns a stream of asynchronus notifications receieved from the server.
fn cancel_data(&self) -> CancelData
Returns information used to cancel pending queries.
Used with the cancel_query
function. The object returned can be used
to cancel any query executed by the connection it was created from.
fn parameter(&self, param: &str) -> Option<&str>
Returns the value of the specified Postgres backend parameter, such as
timezone
or server_version
.