Type Alias Connection

Source
pub type Connection = PgConnection;

Aliased Type§

struct Connection { /* private fields */ }

Implementations

Source§

impl PgConnection

Source

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(()))
Source

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

Source§

type Backend = Pg

The backend this type connects to
Source§

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>

Establishes a new connection to the database Read more
Source§

fn execute_returning_count<T>(&mut self, source: &T) -> Result<usize, Error>
where T: QueryFragment<Pg> + QueryId,

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 AnsiTransactionManager

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)

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)

Set a specific Instrumentation implementation for this connection
Source§

fn set_prepared_statement_cache_size(&mut self, size: CacheSize)

Set the prepared statement cache size to CacheSize for this connection
Source§

fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
where F: FnOnce(&mut Self) -> Result<T, E>, E: From<Error>,

Executes the given function inside of a database transaction Read more
Source§

fn begin_test_transaction(&mut self) -> Result<(), Error>

Creates a transaction that will never be committed. This is useful for tests. Panics if called while inside of a transaction or if called with a connection containing a broken transaction
Source§

fn test_transaction<T, E, F>(&mut self, f: F) -> T
where F: FnOnce(&mut Self) -> Result<T, E>, E: Debug,

Executes the given function inside a transaction, but does not commit it. Panics if the given function returns an error. Read more
Source§

impl GetPgMetadataCache for PgConnection

Source§

fn get_metadata_cache(&mut self) -> &mut PgMetadataCache

Get the PgMetadataCache
Source§

impl<B> LoadConnection<B> for PgConnection
where PgConnection: PgLoadingMode<B>,

Source§

type Cursor<'conn, 'query> = <PgConnection as PgLoadingMode<B>>::Cursor<'conn, 'query>

The cursor type returned by LoadConnection::load Read more
Source§

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>

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

Source§

fn setup(&mut self) -> Result<usize, Error>

Setup the following table: Read more
Source§

impl MultiConnectionHelper for PgConnection

Source§

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>

Get the lookup type from any
Source§

impl R2D2Connection for PgConnection

Source§

fn ping(&mut self) -> Result<(), Error>

Check if a connection is still valid
Source§

fn is_broken(&mut self) -> bool

Checks if the connection is broken and should not be reused Read more
Source§

impl SimpleConnection for PgConnection

Source§

fn batch_execute(&mut self, query: &str) -> Result<(), Error>

Execute multiple SQL statements within the same string. Read more
Source§

impl<'b, Changes, Output> UpdateAndFetchResults<Changes, Output> for PgConnection
where 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>

See the traits documentation.
Source§

impl ConnectionSealed for PgConnection

Source§

impl Send for PgConnection