pub struct TransactionConfig { /* private fields */ }Expand description
Options for starting a PostgreSQL transaction: isolation level, access
mode and DEFERRABLE.
The default leaves every choice to the server. Use Self::builder when
the choices are known in code; it only offers .deferrable() after
.serializable().read_only(), the only combination where PostgreSQL
gives DEFERRABLE a meaning. Use the setters on this type for choices
made at runtime.
§Examples
use drizzle_postgres::{AccessMode, IsolationLevel, TransactionConfig};
let config = TransactionConfig::builder()
.serializable()
.read_only()
.deferrable()
.build();
assert_eq!(config.isolation(), Some(IsolationLevel::Serializable));
assert_eq!(config.access(), Some(AccessMode::ReadOnly));
assert!(config.is_deferrable());
// Runtime choices:
let config = TransactionConfig::new().isolation_level(IsolationLevel::RepeatableRead);
assert_eq!(config.access(), None); // server default§Compile-time checks
use drizzle_postgres::TransactionConfig;
// DEFERRABLE only has meaning for a serializable, read-only transaction.
let _ = TransactionConfig::builder()
.serializable()
.read_write()
.deferrable();Implementations§
Source§impl TransactionConfig
impl TransactionConfig
Sourcepub const fn builder() -> ConfigBuilder
pub const fn builder() -> ConfigBuilder
Starts a ConfigBuilder, which checks option combinations at compile time.
Sourcepub const fn isolation_level(self, level: IsolationLevel) -> Self
pub const fn isolation_level(self, level: IsolationLevel) -> Self
Sets the isolation level.
Any level other than SERIALIZABLE turns DEFERRABLE off.
Sourcepub const fn access_mode(self, mode: AccessMode) -> Self
pub const fn access_mode(self, mode: AccessMode) -> Self
Sets the access mode.
READ WRITE turns DEFERRABLE off.
Sourcepub const fn deferrable(self) -> Self
pub const fn deferrable(self) -> Self
Makes the transaction SERIALIZABLE READ ONLY DEFERRABLE.
DEFERRABLE only has a meaning for a serializable, read-only
transaction, so this also sets those two options. Prefer the builder
when the choices are known in code.
Sourcepub const fn isolation(&self) -> Option<IsolationLevel>
pub const fn isolation(&self) -> Option<IsolationLevel>
Returns the isolation level, or None for the server default.
Sourcepub const fn access(&self) -> Option<AccessMode>
pub const fn access(&self) -> Option<AccessMode>
Returns the access mode, or None for the server default.
Sourcepub const fn is_deferrable(&self) -> bool
pub const fn is_deferrable(&self) -> bool
Returns true if DEFERRABLE is set.