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, 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 value 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.