@@ -224,25 +224,17 @@ impl Handle {
224
224
& self ,
225
225
behaviour : TransactionBehavior ,
226
226
) -> rusqlite:: Result < OwnedTx > {
227
- unsafe {
228
- Ok ( self
229
- . start_transaction ( |conn, handle| {
230
- let conn_ptr = std:: ptr:: from_mut ( conn) ;
231
- let conn_void_ptr: CanSend < * mut ( ) > = std:: mem:: transmute ( conn_ptr) ;
232
- type TxRes < ' a > = rusqlite:: Result < rusqlite:: Transaction < ' a > > ;
233
- let tx_thread = std:: thread:: spawn ( move ||{
234
- eprintln ! ( "hello from transaction thread" ) ;
235
- let conn: & mut Connection = std:: mem:: transmute ( conn_void_ptr) ;
236
- let tx_res: TxRes = conn. transaction_with_behavior ( behaviour) ;
237
- CanSend ( Box :: into_raw ( Box :: new ( tx_res) ) )
238
- } ) ;
239
- let rtx_raw = tx_thread. join ( ) . unwrap ( ) ;
240
- eprintln ! ( "joined transaction thread" ) ;
241
- let rtx = Box :: from_raw ( rtx_raw. 0 as * mut TxRes ) ;
242
- Ok ( Transaction :: new ( ( * rtx) ?, handle) )
243
- } ) ?
244
- . into ( ) )
245
- }
227
+ Ok ( self
228
+ . start_transaction ( |conn, handle| {
229
+ let tx_thread = run_blocking ( || {
230
+ eprintln ! ( "hello from transaction thread" ) ;
231
+ conn. transaction_with_behavior ( behaviour) . map ( CanSend )
232
+ } ) ;
233
+ eprintln ! ( "joined transaction thread" ) ;
234
+ let rtx = tx_thread?. 0 ;
235
+ Ok ( Transaction :: new ( rtx, handle) )
236
+ } ) ?
237
+ . into ( ) )
246
238
}
247
239
248
240
/// Starts a deferred transaction (the default). There is no guaranteed read-only transaction
@@ -274,15 +266,6 @@ impl Handle {
274
266
Ok ( reader)
275
267
}
276
268
277
- // pub(crate) fn associated_read<'h, H>(handle: H) -> rusqlite::Result<Reader<'h, H>> where H: WithHandle {
278
- // let reader = Reader {
279
- // owned_tx: handle.as_ref().start_deferred_transaction()?,
280
- // handle,
281
- // reads: Default::default(),
282
- // };
283
- // Ok(reader)
284
- // }
285
-
286
269
pub fn read_single ( & self , key : & [ u8 ] ) -> Result < Option < SnapshotValue < Value > > > {
287
270
let mut reader = self . read ( ) ?;
288
271
let Some ( value) = reader. add ( key) ? else {
@@ -467,9 +450,9 @@ impl Handle {
467
450
Ok ( ( ) )
468
451
}
469
452
470
- pub fn delete_prefix ( & self , prefix : & [ u8 ] ) -> PubResult < ( ) > {
453
+ pub fn delete_prefix ( & self , prefix : impl AsRef < [ u8 ] > ) -> PubResult < ( ) > {
471
454
let mut tx = self . start_deferred_transaction ( ) ?;
472
- for item in tx. list_items ( prefix) ? {
455
+ for item in tx. list_items ( prefix. as_ref ( ) ) ? {
473
456
tx. delete_key ( & item. key ) ?;
474
457
}
475
458
tx. commit ( ) ?. complete ( ) ;
@@ -583,4 +566,4 @@ impl AsRef<Handle> for Rc<RwLockReadGuard<'_, Handle>> {
583
566
584
567
struct CanSend < T > ( T ) ;
585
568
586
- unsafe impl < T > Send for CanSend < T > { }
569
+ unsafe impl < T > Send for CanSend < T > { }
0 commit comments