pub struct PgConnection { /* private fields */ }Expand description
The connection string expected by PgConnection::establish
should be a PostgreSQL connection string, as documented at
https://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNSTRING
Supported loading model implementations
If you are unsure which loading mode is the correct one for your application,
you likely want to use the DefaultLoadingMode as that one offers
generally better performance.
Due to the fact that PgConnection supports multiple loading modes
it is required to always specify the used loading mode
when calling RunQueryDsl::load_iter
DefaultLoadingMode
By using this mode PgConnection defaults to loading all response values at once
and only performs deserialization afterward for the DefaultLoadingMode.
Generally this mode will be more performant as it.
This loading mode allows users to perform hold more than one iterator at once using the same connection:
use diesel::connection::DefaultLoadingMode;
let iter1 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;
let iter2 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;
for r in iter1 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}
for r in iter2 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}PgRowByRowLoadingMode
By using this mode PgConnection defaults to loading each row of the result set
sepreatly. This might be desired for huge result sets.
This loading mode prevents creating more than one iterator at once using the same connection. The following code is not allowed:
use diesel::pg::PgRowByRowLoadingMode;
let iter1 = users::table.load_iter::<(i32, String), PgRowByRowLoadingMode>(connection)?;
// creating a second iterator generates an compiler error
let iter2 = users::table.load_iter::<(i32, String), PgRowByRowLoadingMode>(connection)?;
for r in iter1 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}
for r in iter2 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}Implementations
sourceimpl 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(()))Trait Implementations
sourceimpl Connection for PgConnection
impl Connection for PgConnection
sourcefn establish(database_url: &str) -> Result<PgConnection, ConnectionError>
fn establish(database_url: &str) -> Result<PgConnection, ConnectionError>
sourcefn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>where
F: FnOnce(&mut Self) -> Result<T, E>,
E: From<Error>,
fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>where
F: FnOnce(&mut Self) -> Result<T, E>,
E: From<Error>,
sourceimpl MigrationConnection for PgConnection
impl MigrationConnection for PgConnection
sourceimpl SimpleConnection for PgConnection
impl SimpleConnection for PgConnection
sourceimpl<'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, NoReturningClause>: LoadQuery<'b, PgConnection, Output, DefaultLoadingMode>,
<<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, NoReturningClause>: LoadQuery<'b, PgConnection, Output, DefaultLoadingMode>,
<<Changes as HasTable>::Table as Table>::AllColumns: ValidGrouping<()>,
<<<Changes as HasTable>::Table as Table>::AllColumns as ValidGrouping<()>>::IsAggregate: MixedAggregates<No, Output = No>,
sourcefn update_and_fetch(&mut self, changeset: Changes) -> Result<Output, Error>
fn update_and_fetch(&mut self, changeset: Changes) -> Result<Output, Error>
impl<B> LoadConnection<B> for PgConnectionwhere
PgConnection: PgLoadingMode<B>,
impl Send for PgConnection
Auto Trait Implementations
impl RefUnwindSafe for PgConnection
impl !Sync for PgConnection
impl Unpin for PgConnection
impl UnwindSafe for PgConnection
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoSql for T
impl<T> IntoSql for T
sourcefn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
self to an expression for Diesel’s query builder. Read moresourcefn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
&self to an expression for Diesel’s query builder. Read moresourceimpl<T> PgMetadataLookup for Twhere
T: Connection<Backend = Pg> + GetPgMetadataCache + LoadConnection<DefaultLoadingMode>,
impl<T> PgMetadataLookup for Twhere
T: Connection<Backend = Pg> + GetPgMetadataCache + LoadConnection<DefaultLoadingMode>,
sourcefn lookup_type(&mut self, type_name: &str, schema: Option<&str>) -> PgTypeMetadata
fn lookup_type(&mut self, type_name: &str, schema: Option<&str>) -> PgTypeMetadata
type_name Read more