@@ -226,7 +226,15 @@ impl Handle {
226
226
) -> rusqlite:: Result < OwnedTx > {
227
227
Ok ( self
228
228
. start_transaction ( |conn, handle| {
229
- let rtx = conn. transaction_with_behavior ( behaviour) ?;
229
+ let tx_res = run_blocking ( || {
230
+ // We're holding the write lock around the Connection, I think we're safe to
231
+ // pass it to another thread. For some reason the return type, the
232
+ // rusqlite::Transaction is what spits the dummy. It doesn't implement Send,
233
+ // even though it only has a reference to Connection internally. So we put it
234
+ // inside CanSend to return it from the thread then pop it out.
235
+ conn. transaction_with_behavior ( behaviour) . map ( CanSend )
236
+ } ) ;
237
+ let rtx = tx_res?. 0 ;
230
238
Ok ( Transaction :: new ( rtx, handle) )
231
239
} ) ?
232
240
. into ( ) )
@@ -261,15 +269,6 @@ impl Handle {
261
269
Ok ( reader)
262
270
}
263
271
264
- // pub(crate) fn associated_read<'h, H>(handle: H) -> rusqlite::Result<Reader<'h, H>> where H: WithHandle {
265
- // let reader = Reader {
266
- // owned_tx: handle.as_ref().start_deferred_transaction()?,
267
- // handle,
268
- // reads: Default::default(),
269
- // };
270
- // Ok(reader)
271
- // }
272
-
273
272
pub fn read_single ( & self , key : & [ u8 ] ) -> Result < Option < SnapshotValue < Value > > > {
274
273
let mut reader = self . read ( ) ?;
275
274
let Some ( value) = reader. add ( key) ? else {
@@ -454,9 +453,9 @@ impl Handle {
454
453
Ok ( ( ) )
455
454
}
456
455
457
- pub fn delete_prefix ( & self , prefix : & [ u8 ] ) -> PubResult < ( ) > {
456
+ pub fn delete_prefix ( & self , prefix : impl AsRef < [ u8 ] > ) -> PubResult < ( ) > {
458
457
let mut tx = self . start_deferred_transaction ( ) ?;
459
- for item in tx. list_items ( prefix) ? {
458
+ for item in tx. list_items ( prefix. as_ref ( ) ) ? {
460
459
tx. delete_key ( & item. key ) ?;
461
460
}
462
461
tx. commit ( ) ?. complete ( ) ;
@@ -567,3 +566,7 @@ impl AsRef<Handle> for Rc<RwLockReadGuard<'_, Handle>> {
567
566
self . deref ( )
568
567
}
569
568
}
569
+
570
+ struct CanSend < T > ( T ) ;
571
+
572
+ unsafe impl < T > Send for CanSend < T > { }
0 commit comments