Skip to main content

Db

Struct Db 

Source
pub struct Db { /* private fields */ }
Expand description

The application’s database, registered as a singleton in providers().

Implementations§

Source§

impl Db

Source

pub async fn connect(url: impl Into<String>) -> Result<Self>

Source

pub async fn in_memory() -> Result<Self>

An isolated in-memory SQLite database.

The pool is capped at one connection deliberately: SQLite gives every connection its own :memory: database, so a larger pool would hand out connections that cannot see each other’s tables.

Source

pub fn from_connection(connection: DatabaseConnection) -> Self

Source

pub fn connection(&self) -> &DatabaseConnection

Source

pub async fn scope<T>(&self, work: impl Future<Output = T>) -> T

Run work with this database ambient, so User::find(..) inside it resolves. The request adapter wraps every action in one of these.

Source

pub async fn rollback_scope<T>( &self, work: impl AsyncFnOnce() -> T, ) -> Result<T>

Run work inside a transaction that is always rolled back.

This is the harness behind #[luxid::test]: tests share one database, run in parallel, and leave nothing behind — no truncation, no fixtures, no ordering constraints.

Source

pub async fn transaction<T>( &self, work: impl AsyncFnOnce() -> Result<T>, ) -> Result<T>

Run work in a transaction, committing on Ok and rolling back on Err.

Source§

impl Db

Source

pub async fn migrate<M: MigratorTrait>(&self) -> Result<()>

Apply every pending migration.

Source

pub async fn migrate_steps<M: MigratorTrait>(&self, steps: u32) -> Result<()>

Apply at most steps pending migrations.

Source

pub async fn rollback<M: MigratorTrait>(&self, steps: u32) -> Result<()>

Roll back the last steps applied migrations.

Source

pub async fn migrate_fresh<M: MigratorTrait>(&self) -> Result<()>

Drop everything and migrate from scratch. Never run this against data you want to keep.

Source

pub async fn migration_status<M: MigratorTrait>( &self, ) -> Result<Vec<MigrationState>>

Every migration and whether it has been applied, in declaration order.

Source

pub async fn has_pending_migrations<M: MigratorTrait>(&self) -> Result<bool>

Whether anything is waiting to run — worth checking at boot.

Source§

impl Db

Source

pub async fn tables(&self) -> Result<Vec<Table>>

Every user table in the database, with its columns.

Migration bookkeeping tables are excluded — nobody wants a factory for seaql_migrations.

Trait Implementations§

Source§

impl Clone for Db

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Db

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more