@@ -58,7 +58,7 @@ pub trait LibsqlInterface {
5858 fn get_json_request (
5959 & self ,
6060 sql : & str ,
61- params : Vec < serde_json:: Value > ,
61+ params : & Vec < serde_json:: Value > ,
6262 baton : Option < & String > ,
6363 is_transacting : bool ,
6464 ) -> serde_json:: Value ;
@@ -67,7 +67,7 @@ pub trait LibsqlInterface {
6767
6868 async fn send (
6969 & mut self ,
70- request : serde_json:: Value ,
70+ request : & mut serde_json:: Value ,
7171 ) -> Result < RemoteSqliteResponse , SqliteError > ;
7272}
7373
@@ -78,17 +78,13 @@ pub enum ActiveStrategy {
7878}
7979
8080pub struct DatabaseConnection {
81- http : HttpStrategy ,
82- websocket : WebSocketStrategy ,
81+ pub http : HttpStrategy ,
82+ pub websocket : WebSocketStrategy ,
8383 pub strategy : ActiveStrategy ,
8484}
8585
8686impl DatabaseConnection {
87- pub async fn open (
88- db_name : & str ,
89- auth : Box < dyn DbAuthStrategy > ,
90- strategy : ActiveStrategy ,
91- ) -> Result < Self , SqliteError > {
87+ pub async fn open ( db_name : & str , auth : Box < dyn DbAuthStrategy > ) -> Result < Self , SqliteError > {
9288 let reqwest_client = reqwest:: Client :: builder ( )
9389 . user_agent ( "libsqlite3_turso/1.0.0" )
9490 . timeout ( std:: time:: Duration :: from_secs ( 30 ) )
@@ -106,21 +102,16 @@ impl DatabaseConnection {
106102 let http = HttpStrategy :: new ( reqwest_client, turso_config. clone ( ) ) ;
107103 let mut websocket = WebSocketStrategy :: new ( turso_config. clone ( ) ) ;
108104
109- if let ActiveStrategy :: Websocket = strategy {
110- websocket. connect ( ) . await ?;
105+ websocket. connect ( ) . await ?;
111106
112- //wait 10 seconds for the server to respond
113- tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) . await ;
114-
115- if cfg ! ( debug_assertions) {
116- println ! ( "WebSocket connection established for {}" , db_name) ;
117- }
107+ if cfg ! ( debug_assertions) {
108+ println ! ( "WebSocket connection established for {}" , db_name) ;
118109 }
119110
120111 Ok ( Self {
121112 http,
122113 websocket,
123- strategy,
114+ strategy : ActiveStrategy :: Websocket ,
124115 } )
125116 }
126117
@@ -133,19 +124,19 @@ impl DatabaseConnection {
133124
134125 pub async fn send (
135126 & mut self ,
136- request : serde_json:: Value ,
127+ mut request : & mut serde_json:: Value ,
137128 ) -> Result < RemoteSqliteResponse , SqliteError > {
138129 match self . strategy {
139- ActiveStrategy :: Http => self . http . send ( request) . await ,
140- ActiveStrategy :: Websocket => self . websocket . send ( request) . await ,
130+ ActiveStrategy :: Http => self . http . send ( & mut request) . await ,
131+ ActiveStrategy :: Websocket => self . websocket . send ( & mut request) . await ,
141132 }
142133 }
143134
144135 pub fn get_json_request (
145136 & self ,
146137 db : & SQLite3 ,
147138 sql : & str ,
148- params : Vec < serde_json:: Value > ,
139+ params : & Vec < serde_json:: Value > ,
149140 ) -> serde_json:: Value {
150141 let baton_str = {
151142 let baton = db. transaction_baton . lock ( ) . unwrap ( ) ;
0 commit comments