pub struct Db { /* private fields */ }Expand description
The database dependency: a cloneable connection handle. Register app-wide
with App::new().extend(db) (or .provide(db) — extend is the §6 seam).
Implementations§
Source§impl Db
impl Db
Sourcepub async fn connect(url: &str) -> Result<Self>
pub async fn connect(url: &str) -> Result<Self>
Connect by URL: sqlite::memory:, sqlite://path.db, postgres://….
Sourcepub async fn from_env() -> Result<Self>
pub async fn from_env() -> Result<Self>
JERRYCAN_DATABASE_URL, defaulting to sqlite::memory: for dev.
Sourcepub fn conn(&self) -> &DatabaseConnection
pub fn conn(&self) -> &DatabaseConnection
The underlying sea-orm connection. Generated repos and migrations execute
through this handle (execute_unprepared, query_one, …).
pub fn backend(&self) -> Backend
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
The URL this handle connected with. Extension crates (jerrycan-realtime) use it to open sessions the pool cannot serve: LISTEN connections, the replication socket, and long-held advisory-lock sessions.
Sourcepub fn sql(&self, query: &str) -> String
pub fn sql(&self, query: &str) -> String
Backend-correct placeholders for a ?-style query string.
Sourcepub fn query_builder(&self) -> &'static dyn QueryBuilder
pub fn query_builder(&self) -> &'static dyn QueryBuilder
The sea-query builder matching this connection’s dialect. Generated repos
pass it to build_any so one builder call renders correct SQL
(placeholders, RETURNING, quoting) for whichever engine is connected.
Source§impl Db
impl Db
Sourcepub async fn migrate(&self, migrations: &[Migration]) -> Result<Vec<String>>
pub async fn migrate(&self, migrations: &[Migration]) -> Result<Vec<String>>
Apply pending migrations in slice order; returns the names applied.
Tracking table _jerrycan_migrations remembers what ran. The whole run
is atomic and concurrency-safe: it runs in one transaction guarded by
a Postgres advisory lock, so several app instances booting at once can’t
race the not-yet-applied check and double-apply the DDL — a failure rolls
the entire run back (all-or-nothing; no half-migrated state).
Sourcepub async fn migrate_owned(
&self,
migrations: &[OwnedMigration],
) -> Result<Vec<String>>
pub async fn migrate_owned( &self, migrations: &[OwnedMigration], ) -> Result<Vec<String>>
Owned-migration twin of migrate — same runner.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Db
impl !UnwindSafe for Db
impl Freeze for Db
impl Send for Db
impl Sync for Db
impl Unpin for Db
impl UnsafeUnpin for Db
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,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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