@@ -15,7 +15,7 @@ use std::sync::{
1515use std:: time:: Duration ;
1616use tokio:: sync:: Mutex ;
1717
18- use super :: transaction:: SyncedTx ;
18+ use super :: { statement :: SyncedStatement , transaction:: SyncedTx } ;
1919
2020#[ derive( Clone ) ]
2121pub struct SyncedConnection {
@@ -110,9 +110,10 @@ impl Conn for SyncedConnection {
110110
111111 async fn execute_batch ( & self , sql : & str ) -> Result < BatchRows > {
112112 if self . should_execute_local ( sql) . await ? {
113- if self . needs_pull . swap ( false , Ordering :: Relaxed ) {
113+ if self . needs_pull . load ( Ordering :: Relaxed ) {
114114 let mut context = self . context . lock ( ) . await ;
115115 crate :: sync:: try_pull ( & mut context, & self . local ) . await ?;
116+ self . needs_pull . store ( false , Ordering :: Relaxed ) ;
116117 }
117118 self . local . execute_batch ( sql)
118119 } else {
@@ -122,9 +123,10 @@ impl Conn for SyncedConnection {
122123
123124 async fn execute_transactional_batch ( & self , sql : & str ) -> Result < BatchRows > {
124125 if self . should_execute_local ( sql) . await ? {
125- if self . needs_pull . swap ( false , Ordering :: Relaxed ) {
126+ if self . needs_pull . load ( Ordering :: Relaxed ) {
126127 let mut context = self . context . lock ( ) . await ;
127128 crate :: sync:: try_pull ( & mut context, & self . local ) . await ?;
129+ self . needs_pull . store ( false , Ordering :: Relaxed ) ;
128130 }
129131 self . local . execute_transactional_batch ( sql) ?;
130132 Ok ( BatchRows :: empty ( ) )
@@ -135,12 +137,17 @@ impl Conn for SyncedConnection {
135137
136138 async fn prepare ( & self , sql : & str ) -> Result < Statement > {
137139 if self . should_execute_local ( sql) . await ? {
138- if self . needs_pull . swap ( false , Ordering :: Relaxed ) {
139- let mut context = self . context . lock ( ) . await ;
140- crate :: sync:: try_pull ( & mut context, & self . local ) . await ?;
141- }
142- Ok ( Statement {
140+ let stmt = Statement {
143141 inner : Box :: new ( LibsqlStmt ( self . local . prepare ( sql) ?) ) ,
142+ } ;
143+
144+ Ok ( Statement {
145+ inner : Box :: new ( SyncedStatement {
146+ conn : self . local . clone ( ) ,
147+ inner : stmt,
148+ context : self . context . clone ( ) ,
149+ needs_pull : self . needs_pull . clone ( ) ,
150+ } ) ,
144151 } )
145152 } else {
146153 let stmt = Statement {
0 commit comments