TransactionMigrate

Struct TransactionMigrate 

Source
pub struct TransactionMigrate<FromSchema> { /* private fields */ }
Expand description

Transaction type for use in migrations.

Implementations§

Source§

impl<FromSchema: 'static> TransactionMigrate<FromSchema>

Source

pub fn migrate_optional<'t, M: Migration<FromSchema = FromSchema>>( &'t mut self, f: impl FnMut(Lazy<'t, M::From>) -> Option<M>, ) -> Result<(), M::Conflict>

Migrate some rows to the new schema.

This will return an error when there is a conflict. The error type depends on the number of unique constraints that the migration can violate:

  • 0 => Infallible
  • 1.. => TableRow<T::From> (row in the old table that could not be migrated)
Source

pub fn migrate<'t, M: Migration<FromSchema = FromSchema>>( &'t mut self, f: impl FnMut(Lazy<'t, M::From>) -> M, ) -> Result<Migrated<'static, FromSchema, M::To>, M::Conflict>

Migrate all rows to the new schema.

Conflict errors work the same as in Self::migrate_optional.

However, this method will return Migrated when all rows are migrated. This can then be used as proof that there will be no foreign key violations.

Source

pub fn migrate_ok<'t, M: Migration<FromSchema = FromSchema, Conflict = Infallible>>( &'t mut self, f: impl FnMut(Lazy<'t, M::From>) -> M, ) -> Migrated<'static, FromSchema, M::To>

Helper method for Self::migrate.

It can only be used when the migration is known to never cause unique constraint conflicts.

Methods from Deref<Target = Transaction<FromSchema>>§

Source

pub fn query<'t, F, R>(&'t self, f: F) -> R
where F: for<'inner> FnOnce(&mut Query<'t, 'inner, S>) -> R,

Execute a query with multiple results.

let user_names = txn.query(|rows| {
    let user = rows.join(User);
    rows.into_vec(&user.name)
});
assert_eq!(user_names, vec!["Alice".to_owned()]);
Source

pub fn query_one<O: 'static>( &self, val: impl IntoSelect<'static, S, Out = O>, ) -> O

Retrieve a single result from the database.

let res = txn.query_one("test".into_expr());
assert_eq!(res, "test");

Instead of using Self::query_one in a loop, it is better to call Self::query and return all results at once.

Source

pub fn lazy<'t, T: MyTyp>( &'t self, val: impl IntoExpr<'static, S, Typ = T>, ) -> T::Lazy<'t>

Source

pub fn lazy_iter<'t, T: Table<Schema = S>>( &'t self, val: impl Joinable<'static, Typ = T>, ) -> LazyIter<'t, T>

Trait Implementations§

Source§

impl<FromSchema> Deref for TransactionMigrate<FromSchema>

Source§

type Target = Transaction<FromSchema>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<FromSchema> !Freeze for TransactionMigrate<FromSchema>

§

impl<FromSchema> RefUnwindSafe for TransactionMigrate<FromSchema>
where FromSchema: RefUnwindSafe,

§

impl<FromSchema> !Send for TransactionMigrate<FromSchema>

§

impl<FromSchema> !Sync for TransactionMigrate<FromSchema>

§

impl<FromSchema> Unpin for TransactionMigrate<FromSchema>
where FromSchema: Unpin,

§

impl<FromSchema> UnwindSafe for TransactionMigrate<FromSchema>
where FromSchema: UnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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