pub struct TransactionMigrate<FromSchema> { /* private fields */ }Expand description
Transaction type for use in migrations.
Implementations§
Source§impl<FromSchema: 'static> TransactionMigrate<FromSchema>
impl<FromSchema: 'static> TransactionMigrate<FromSchema>
Sourcepub fn migrate_optional<'t, M: Migration<FromSchema = FromSchema>>(
&'t mut self,
f: impl FnMut(Lazy<'t, M::From>) -> Option<M>,
) -> Result<(), M::Conflict>
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)
Sourcepub 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>
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.
Sourcepub 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>
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>>§
Sourcepub fn query<'t, F, R>(&'t self, f: F) -> R
pub fn query<'t, F, R>(&'t self, f: F) -> 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()]);Sourcepub fn query_one<O: 'static>(
&self,
val: impl IntoSelect<'static, S, Out = O>,
) -> O
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.