pub struct TransactionMigrate<FromSchema: 'static> { /* 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, T: Migrateable<FromSchema = FromSchema>>(
&'t mut self,
f: impl FnMut(Lazy<'t, T::MigrateFrom>) -> Option<T::Migration>,
) -> Result<MigratedOptional<T>, T::MigrateConflict>
pub fn migrate_optional<'t, T: Migrateable<FromSchema = FromSchema>>( &'t mut self, f: impl FnMut(Lazy<'t, T::MigrateFrom>) -> Option<T::Migration>, ) -> Result<MigratedOptional<T>, T::MigrateConflict>
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 (row in the old table that could not be migrated)
The closure returns Option to indicate if each row must be kept.
Sourcepub fn migrate<'t, T: Migrateable<FromSchema = FromSchema>>(
&'t mut self,
f: impl FnMut(Lazy<'t, T::MigrateFrom>) -> T::Migration,
) -> Result<Migrated<'static, T>, T::MigrateConflict>
pub fn migrate<'t, T: Migrateable<FromSchema = FromSchema>>( &'t mut self, f: impl FnMut(Lazy<'t, T::MigrateFrom>) -> T::Migration, ) -> Result<Migrated<'static, T>, T::MigrateConflict>
Migrate all rows to the new schema.
Same as Self::migrate_optional, but it does not require wrapping all migrated rows in Some.
This is most likely the variant that you want to use, unless you have a table without unique constraint, see Self::migrate_ok.
Sourcepub fn migrate_ok<'t, T: Migrateable<FromSchema = FromSchema, MigrateConflict = Infallible>>(
&'t mut self,
f: impl FnMut(Lazy<'t, T::MigrateFrom>) -> T::Migration,
) -> Migrated<'static, T>
pub fn migrate_ok<'t, T: Migrateable<FromSchema = FromSchema, MigrateConflict = Infallible>>( &'t mut self, f: impl FnMut(Lazy<'t, T::MigrateFrom>) -> T::Migration, ) -> Migrated<'static, T>
Migrate all rows to the new schema, without unique constraint conflicts.
Same as Self::migrate, but 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, R>(&'t self, f: impl FnOnce(&mut Query<'t, '_, S>) -> R) -> R
pub fn query<'t, R>(&'t self, f: impl FnOnce(&mut Query<'t, '_, S>) -> R) -> 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.
Sourcepub fn lazy<'t, T: OptTable<Schema = S>>(
&'t self,
val: impl IntoExpr<'static, S, Typ = T>,
) -> T::Lazy<'t>
pub fn lazy<'t, T: OptTable<Schema = S>>( &'t self, val: impl IntoExpr<'static, S, Typ = T>, ) -> T::Lazy<'t>
Retrieve a crate::Lazy or Option<Lazy> from the database.
This is very similar to Self::query_one, except that it retrieves crate::Lazy instead of TableRow. As such it only works with table valued rust_query::Expr.
let cat = txn.insert_ok(Author {
name: "Cat".to_owned()
});
let blog_post = txn.insert_ok(Page {
content: "Hello world!".to_owned(),
title: "Hi".to_owned(),
author: cat,
});
let lazy_post = txn.lazy(blog_post);
println!("{}:", lazy_post.title);
println!("{}", lazy_post.content);
println!("written by: {}", lazy_post.author.name);Sourcepub fn lazy_iter<'t, T: Table<Schema = S>>(
&'t self,
val: impl IntoJoinable<'static, S, Typ = TableRow<T>>,
) -> LazyIter<'t, T>
pub fn lazy_iter<'t, T: Table<Schema = S>>( &'t self, val: impl IntoJoinable<'static, S, Typ = TableRow<T>>, ) -> LazyIter<'t, T>
This retrieves an iterator of crate::Lazy values.
Refer to Rows::join for the kind of the parameter that is supported here. Refer to Transaction::lazy for the single row version.