pub type Connection = PgConnection;
Aliased Type§
struct Connection { /* private fields */ }
Implementations
Source§impl PgConnection
impl PgConnection
Sourcepub fn build_transaction(&mut self) -> TransactionBuilder<'_, PgConnection>
pub fn build_transaction(&mut self) -> TransactionBuilder<'_, PgConnection>
Build a transaction, specifying additional details such as isolation level
See TransactionBuilder
for more examples.
conn.build_transaction()
.read_only()
.serializable()
.deferrable()
.run(|conn| Ok(()))
Sourcepub fn notifications_iter(
&mut self,
) -> impl Iterator<Item = Result<PgNotification, Error>>
pub fn notifications_iter( &mut self, ) -> impl Iterator<Item = Result<PgNotification, Error>>
See Postgres documentation for SQL commands NOTIFY and LISTEN
The returned iterator can yield items even after a None value when new notifications have been received.
The iterator can be polled again after a None
value was received as new notifications might have
been send in the mean time.
§Example
// register the notifications channel we want to receive notifications for
diesel::sql_query("LISTEN example_channel").execute(connection)?;
// send some notification
// this is usually done from a different connection/thread/application
diesel::sql_query("NOTIFY example_channel, 'additional data'").execute(connection)?;
for result in connection.notifications_iter() {
let notification = result.unwrap();
assert_eq!(notification.channel, "example_channel");
assert_eq!(notification.payload, "additional data");
println!(
"Notification received from server process with id {}.",
notification.process_id
);
}
Trait Implementations
Source§impl Connection for PgConnection
impl Connection for PgConnection
Source§type TransactionManager = AnsiTransactionManager
type TransactionManager = AnsiTransactionManager
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.The transaction manager implementation used by this connection
Source§fn establish(database_url: &str) -> Result<PgConnection, ConnectionError>
fn establish(database_url: &str) -> Result<PgConnection, ConnectionError>
Establishes a new connection to the database Read more
Source§fn execute_returning_count<T>(&mut self, source: &T) -> Result<usize, Error>
fn execute_returning_count<T>(&mut self, source: &T) -> Result<usize, Error>
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.Execute a single SQL statements given by a query and return
number of affected rows
Source§fn transaction_state(&mut self) -> &mut AnsiTransactionManagerwhere
PgConnection: Sized,
fn transaction_state(&mut self) -> &mut AnsiTransactionManagerwhere
PgConnection: Sized,
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.Get access to the current transaction state of this connection Read more
Source§fn instrumentation(&mut self) -> &mut (dyn Instrumentation + 'static)
fn instrumentation(&mut self) -> &mut (dyn Instrumentation + 'static)
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.Get the instrumentation instance stored in this connection
Source§fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)
fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)
Set a specific
Instrumentation
implementation for this connectionSource§fn set_prepared_statement_cache_size(&mut self, size: CacheSize)
fn set_prepared_statement_cache_size(&mut self, size: CacheSize)
Set the prepared statement cache size to
CacheSize
for this connectionSource§fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
Executes the given function inside of a database transaction Read more
Source§impl GetPgMetadataCache for PgConnection
impl GetPgMetadataCache for PgConnection
Source§fn get_metadata_cache(&mut self) -> &mut PgMetadataCache
fn get_metadata_cache(&mut self) -> &mut PgMetadataCache
Get the
PgMetadataCache
Source§impl<B> LoadConnection<B> for PgConnectionwhere
PgConnection: PgLoadingMode<B>,
impl<B> LoadConnection<B> for PgConnectionwhere
PgConnection: PgLoadingMode<B>,
Source§type Cursor<'conn, 'query> = <PgConnection as PgLoadingMode<B>>::Cursor<'conn, 'query>
type Cursor<'conn, 'query> = <PgConnection as PgLoadingMode<B>>::Cursor<'conn, 'query>
The cursor type returned by
LoadConnection::load
Read moreSource§type Row<'conn, 'query> = <PgConnection as PgLoadingMode<B>>::Row<'conn, 'query>
type Row<'conn, 'query> = <PgConnection as PgLoadingMode<B>>::Row<'conn, 'query>
The row type used as
Iterator::Item
for the iterator implementation
of LoadConnection::Cursor
Source§fn load<'conn, 'query, T>(
&'conn mut self,
source: T,
) -> Result<<PgConnection as LoadConnection<B>>::Cursor<'conn, 'query>, Error>where
T: Query + QueryFragment<<PgConnection as Connection>::Backend> + QueryId + 'query,
<PgConnection as Connection>::Backend: QueryMetadata<<T as Query>::SqlType>,
fn load<'conn, 'query, T>(
&'conn mut self,
source: T,
) -> Result<<PgConnection as LoadConnection<B>>::Cursor<'conn, 'query>, Error>where
T: Query + QueryFragment<<PgConnection as Connection>::Backend> + QueryId + 'query,
<PgConnection as Connection>::Backend: QueryMetadata<<T as Query>::SqlType>,
Available on crate feature
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.Executes a given query and returns any requested values Read more
Source§impl MigrationConnection for PgConnection
impl MigrationConnection for PgConnection
Source§impl MultiConnectionHelper for PgConnection
impl MultiConnectionHelper for PgConnection
Source§fn to_any<'a>(
lookup: &mut <<PgConnection as Connection>::Backend as TypeMetadata>::MetadataLookup,
) -> &mut (dyn Any + 'a)
fn to_any<'a>( lookup: &mut <<PgConnection as Connection>::Backend as TypeMetadata>::MetadataLookup, ) -> &mut (dyn Any + 'a)
Convert the lookup type to any
Source§fn from_any(
lookup: &mut (dyn Any + 'static),
) -> Option<&mut <<PgConnection as Connection>::Backend as TypeMetadata>::MetadataLookup>
fn from_any( lookup: &mut (dyn Any + 'static), ) -> Option<&mut <<PgConnection as Connection>::Backend as TypeMetadata>::MetadataLookup>
Get the lookup type from any
Source§impl R2D2Connection for PgConnection
impl R2D2Connection for PgConnection
Source§impl SimpleConnection for PgConnection
impl SimpleConnection for PgConnection
Source§impl<'b, Changes, Output> UpdateAndFetchResults<Changes, Output> for PgConnectionwhere
Changes: Copy + AsChangeset<Target = <Changes as HasTable>::Table> + IntoUpdateTarget,
UpdateStatement<<Changes as HasTable>::Table, <Changes as IntoUpdateTarget>::WhereClause, <Changes as AsChangeset>::Changeset>: LoadQuery<'b, PgConnection, Output>,
<<Changes as HasTable>::Table as Table>::AllColumns: ValidGrouping<()>,
<<<Changes as HasTable>::Table as Table>::AllColumns as ValidGrouping<()>>::IsAggregate: MixedAggregates<No, Output = No>,
impl<'b, Changes, Output> UpdateAndFetchResults<Changes, Output> for PgConnectionwhere
Changes: Copy + AsChangeset<Target = <Changes as HasTable>::Table> + IntoUpdateTarget,
UpdateStatement<<Changes as HasTable>::Table, <Changes as IntoUpdateTarget>::WhereClause, <Changes as AsChangeset>::Changeset>: LoadQuery<'b, PgConnection, Output>,
<<Changes as HasTable>::Table as Table>::AllColumns: ValidGrouping<()>,
<<<Changes as HasTable>::Table as Table>::AllColumns as ValidGrouping<()>>::IsAggregate: MixedAggregates<No, Output = No>,
Source§fn update_and_fetch(&mut self, changeset: Changes) -> Result<Output, Error>
fn update_and_fetch(&mut self, changeset: Changes) -> Result<Output, Error>
See the traits documentation.