@@ -15,7 +15,7 @@ use std::sync::{
15
15
use std:: time:: Duration ;
16
16
use tokio:: sync:: Mutex ;
17
17
18
- use super :: transaction:: SyncedTx ;
18
+ use super :: { statement :: SyncedStatement , transaction:: SyncedTx } ;
19
19
20
20
#[ derive( Clone ) ]
21
21
pub struct SyncedConnection {
@@ -110,9 +110,10 @@ impl Conn for SyncedConnection {
110
110
111
111
async fn execute_batch ( & self , sql : & str ) -> Result < BatchRows > {
112
112
if self . should_execute_local ( sql) . await ? {
113
- if self . needs_pull . swap ( false , Ordering :: Relaxed ) {
113
+ if self . needs_pull . load ( Ordering :: Relaxed ) {
114
114
let mut context = self . context . lock ( ) . await ;
115
115
crate :: sync:: try_pull ( & mut context, & self . local ) . await ?;
116
+ self . needs_pull . store ( false , Ordering :: Relaxed ) ;
116
117
}
117
118
self . local . execute_batch ( sql)
118
119
} else {
@@ -122,9 +123,10 @@ impl Conn for SyncedConnection {
122
123
123
124
async fn execute_transactional_batch ( & self , sql : & str ) -> Result < BatchRows > {
124
125
if self . should_execute_local ( sql) . await ? {
125
- if self . needs_pull . swap ( false , Ordering :: Relaxed ) {
126
+ if self . needs_pull . load ( Ordering :: Relaxed ) {
126
127
let mut context = self . context . lock ( ) . await ;
127
128
crate :: sync:: try_pull ( & mut context, & self . local ) . await ?;
129
+ self . needs_pull . store ( false , Ordering :: Relaxed ) ;
128
130
}
129
131
self . local . execute_transactional_batch ( sql) ?;
130
132
Ok ( BatchRows :: empty ( ) )
@@ -135,12 +137,17 @@ impl Conn for SyncedConnection {
135
137
136
138
async fn prepare ( & self , sql : & str ) -> Result < Statement > {
137
139
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 {
143
141
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
+ } ) ,
144
151
} )
145
152
} else {
146
153
let stmt = Statement {
0 commit comments