@@ -79,25 +79,20 @@ impl DatabaseConnection {
79
79
& self ,
80
80
) -> Result < DatabaseStorageTransaction < ' _ > , Error > {
81
81
Ok ( DatabaseStorageTransaction {
82
- transaction : Some ( self . conn . transaction ( ) ?) ,
82
+ transaction : self . conn . transaction ( ) ?,
83
83
} )
84
84
}
85
85
}
86
86
87
87
pub ( super ) struct DatabaseStorageTransaction < ' a > {
88
- transaction : Option < Transaction < ' a > > ,
88
+ transaction : Transaction < ' a > ,
89
89
}
90
90
91
91
impl < ' a > StorageTransaction for DatabaseStorageTransaction < ' a > {
92
92
fn store_batch ( & mut self , batch : & [ Blob ] ) -> Result < ( ) , Error > {
93
- let transaction = self
94
- . transaction
95
- . as_ref ( )
96
- . expect ( "called complete() before store_batch()" ) ;
97
-
98
93
for blob in batch {
99
94
let compression = blob. compression . map ( |alg| alg as i32 ) ;
100
- transaction. query (
95
+ self . transaction . query (
101
96
"INSERT INTO files (path, mime, content, compression)
102
97
VALUES ($1, $2, $3, $4)
103
98
ON CONFLICT (path) DO UPDATE
@@ -108,11 +103,8 @@ impl<'a> StorageTransaction for DatabaseStorageTransaction<'a> {
108
103
Ok ( ( ) )
109
104
}
110
105
111
- fn complete ( & mut self ) -> Result < ( ) , Error > {
112
- self . transaction
113
- . take ( )
114
- . expect ( "called complete() multiple times" )
115
- . commit ( ) ?;
106
+ fn complete ( self : Box < Self > ) -> Result < ( ) , Error > {
107
+ self . transaction . commit ( ) ?;
116
108
Ok ( ( ) )
117
109
}
118
110
}
@@ -193,7 +185,7 @@ mod tests {
193
185
} ;
194
186
195
187
let conn = backend. start_connection ( ) ?;
196
- let mut transaction = conn. start_storage_transaction ( ) ?;
188
+ let mut transaction = Box :: new ( conn. start_storage_transaction ( ) ?) ;
197
189
transaction. store_batch ( std:: slice:: from_ref ( & small_blob) ) ?;
198
190
transaction. store_batch ( std:: slice:: from_ref ( & big_blob) ) ?;
199
191
transaction. complete ( ) ?;
0 commit comments