pub struct Repo { /* private fields */ }Expand description
A pool of connections to one database, and optionally to a read
replica of it (see Repo::with_replica).
Implementations§
Source§impl Repo
impl Repo
Sourcepub async fn connect(url: &str) -> Result<Self>
pub async fn connect(url: &str) -> Result<Self>
Connects to postgres://… or sqlite:… URLs. SQLite files (and their
directories) are created if missing; sqlite::memory: gives a private
in-memory database.
Sourcepub async fn from_config(config: &Config) -> Result<Self>
pub async fn from_config(config: &Config) -> Result<Self>
Connects using database.url and optional database.pool_size,
and to a read replica at database.replica_url (with
database.replica_pool_size) when one is set.
Sourcepub async fn from_config_named(config: &Config, name: &str) -> Result<Self>
pub async fn from_config_named(config: &Config, name: &str) -> Result<Self>
Connects to the named database databases.<name>.url (with
pool_size, and replica_url and replica_pool_size for a
replica), for App::named_database.
Sourcepub fn with_replica(self, replica: Repo) -> Self
pub fn with_replica(self, replica: Repo) -> Self
Adds a read replica. Queries read from it in a request that doesn’t
write (a GET or HEAD, unless this browser wrote in the last
two seconds), and in reading blocks; everything else, and every
read after a write, uses the primary.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Which database this is: its URL without user or password
(postgres://db.internal/shop, sqlite://db/development.sqlite3).
Sourcepub fn has_replica(&self) -> bool
pub fn has_replica(&self) -> bool
Whether reads can go to a replica.
Sourcepub fn postgres_pool(&self) -> Option<&PgPool>
pub fn postgres_pool(&self) -> Option<&PgPool>
The underlying sqlx pool when this is a Postgres database, to share
it with other libraries: raw sqlx, or SeaORM 2 (built on the same
sqlx 0.9) through SqlxPostgresConnector::from_sqlx_postgres_pool.
Use glacier::sqlx so the versions match.
Queries made through it don’t join Glacier’s ambient transactions.
Sourcepub fn sqlite_pool(&self) -> Option<&SqlitePool>
pub fn sqlite_pool(&self) -> Option<&SqlitePool>
The underlying sqlx pool when this is a SQLite database; see
Repo::postgres_pool.
Sourcepub async fn close(&self)
pub async fn close(&self)
Closes every connection; later queries fail. For a clean shutdown, once the app has stopped serving.
pub fn dialect(&self) -> Dialect
Sourcepub async fn begin(&self) -> Result<Transaction>
pub async fn begin(&self) -> Result<Transaction>
Starts an explicit transaction. Most code should prefer
db::transaction, which makes it ambient.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Repo
impl !UnwindSafe for Repo
impl Freeze for Repo
impl Send for Repo
impl Sync for Repo
impl Unpin for Repo
impl UnsafeUnpin for Repo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more