pub struct Db { /* private fields */ }Expand description
The database dependency: a cloneable pool 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.
pub fn pool(&self) -> &AnyPool
pub fn backend(&self) -> Backend
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 pool’s dialect. Generated repos
pass it to build_any_sqlx 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. A failure
stops the run and records nothing for the failed entry.
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