@@ -12,7 +12,10 @@ use std::string::ToString;
12
12
pub trait AsyncTransaction {
13
13
type Error : std:: error:: Error + Send + Sync + ' static ;
14
14
15
- async fn execute ( & mut self , query : & [ & str ] ) -> Result < usize , Self :: Error > ;
15
+ async fn execute < ' a , T : Iterator < Item = & ' a str > + Send > (
16
+ & mut self ,
17
+ queries : T ,
18
+ ) -> Result < usize , Self :: Error > ;
16
19
}
17
20
18
21
#[ async_trait]
@@ -43,10 +46,13 @@ async fn migrate<T: AsyncTransaction>(
43
46
migration. set_applied ( ) ;
44
47
let update_query = insert_migration_query ( & migration, migration_table_name) ;
45
48
transaction
46
- . execute ( & [
47
- migration. sql ( ) . as_ref ( ) . expect ( "sql must be Some!" ) ,
48
- & update_query,
49
- ] )
49
+ . execute (
50
+ [
51
+ migration. sql ( ) . as_ref ( ) . expect ( "sql must be Some!" ) ,
52
+ update_query. as_str ( ) ,
53
+ ]
54
+ . into_iter ( ) ,
55
+ )
50
56
. await
51
57
. migration_err (
52
58
& format ! ( "error applying migration {migration}" ) ,
@@ -109,10 +115,8 @@ async fn migrate_grouped<T: AsyncTransaction>(
109
115
) ;
110
116
}
111
117
112
- let refs: Vec < & str > = grouped_migrations. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
113
-
114
118
transaction
115
- . execute ( refs . as_ref ( ) )
119
+ . execute ( grouped_migrations . iter ( ) . map ( AsRef :: as_ref ) )
116
120
. await
117
121
. migration_err ( "error applying migrations" , None ) ?;
118
122
@@ -142,7 +146,7 @@ where
142
146
migration_table_name : & str ,
143
147
) -> Result < Option < Migration > , Error > {
144
148
let mut migrations = self
145
- . query ( Self :: get_last_applied_migration_query ( migration_table_name) . as_str ( ) )
149
+ . query ( Self :: get_last_applied_migration_query ( migration_table_name) . as_ref ( ) )
146
150
. await
147
151
. migration_err ( "error getting last applied migration" , None ) ?;
148
152
@@ -154,7 +158,7 @@ where
154
158
migration_table_name : & str ,
155
159
) -> Result < Vec < Migration > , Error > {
156
160
let migrations = self
157
- . query ( Self :: get_applied_migrations_query ( migration_table_name) . as_str ( ) )
161
+ . query ( Self :: get_applied_migrations_query ( migration_table_name) . as_ref ( ) )
158
162
. await
159
163
. migration_err ( "error getting applied migrations" , None ) ?;
160
164
@@ -170,9 +174,11 @@ where
170
174
target : Target ,
171
175
migration_table_name : & str ,
172
176
) -> Result < Report , Error > {
173
- self . execute ( & [ & Self :: assert_migrations_table_query ( migration_table_name) ] )
174
- . await
175
- . migration_err ( "error asserting migrations table" , None ) ?;
177
+ self . execute (
178
+ [ Self :: assert_migrations_table_query ( migration_table_name) . as_ref ( ) ] . into_iter ( ) ,
179
+ )
180
+ . await
181
+ . migration_err ( "error asserting migrations table" , None ) ?;
176
182
177
183
let applied_migrations = self
178
184
. get_applied_migrations ( migration_table_name)
0 commit comments