1- use std:: collections:: HashMap ;
2- use std:: path:: { Path , PathBuf } ;
3- use std:: time:: Duration ;
4-
51use anyhow:: { anyhow, bail, Context , Result } ;
62use clap:: ValueEnum ;
73use sqlite_watcher:: watcher_proto:: watcher_client:: WatcherClient ;
84use sqlite_watcher:: watcher_proto:: {
95 AckChangesRequest , GetStateRequest , HealthCheckRequest , ListChangesRequest , SetStateRequest ,
106} ;
7+ use std:: collections:: HashMap ;
8+ use std:: path:: { Path , PathBuf } ;
119use tokio_postgres:: Client ;
1210use tonic:: codegen:: InterceptedService ;
1311use tonic:: service:: Interceptor ;
@@ -17,7 +15,6 @@ use tower::service_fn;
1715
1816use crate :: jsonb:: writer:: { delete_jsonb_rows, insert_jsonb_batch, upsert_jsonb_rows} ;
1917
20- const DEFAULT_BATCH_LIMIT : u32 = 500 ;
2118const GLOBAL_STATE_KEY : & str = "_global" ;
2219
2320#[ derive( Debug , Clone , Copy , ValueEnum , PartialEq , Eq ) ]
@@ -63,7 +60,7 @@ pub async fn run(opts: SyncSqliteOptions) -> Result<()> {
6360 let mut processed_any = false ;
6461
6562 loop {
66- let mut req = Request :: new ( ListChangesRequest {
63+ let req = Request :: new ( ListChangesRequest {
6764 limit : opts. batch_size . max ( 1 ) ,
6865 } ) ;
6966 let changes = watcher
@@ -160,8 +157,8 @@ async fn apply_changes(
160157 change. table_name . clone ( ) ,
161158 TableState {
162159 last_change_id : change. change_id ,
163- wal_frame : change. wal_frame . clone ( ) ,
164- cursor : change. cursor . clone ( ) ,
160+ wal_frame : non_empty_string ( & change. wal_frame ) ,
161+ cursor : non_empty_string ( & change. cursor ) ,
165162 } ,
166163 ) ;
167164 }
@@ -235,6 +232,14 @@ fn mode_string(mode: IncrementalMode) -> &'static str {
235232 }
236233}
237234
235+ fn non_empty_string ( value : & str ) -> Option < String > {
236+ if value. is_empty ( ) {
237+ None
238+ } else {
239+ Some ( value. to_owned ( ) )
240+ }
241+ }
242+
238243fn load_token ( path : Option < & Path > ) -> Result < String > {
239244 let token_path = path
240245 . map ( |p| p. to_path_buf ( ) )
@@ -399,17 +404,17 @@ mod tests {
399404 op: "insert" . into( ) ,
400405 primary_key: "1" . into( ) ,
401406 payload: serde_json:: to_vec( & serde_json:: json!( { "a" : 1 } ) ) . unwrap( ) ,
402- wal_frame: None ,
403- cursor: None ,
407+ wal_frame: String :: new ( ) ,
408+ cursor: String :: new ( ) ,
404409 } ,
405410 Change {
406411 change_id: 2 ,
407412 table_name: "foo" . into( ) ,
408413 op: "delete" . into( ) ,
409414 primary_key: "2" . into( ) ,
410415 payload: Vec :: new( ) ,
411- wal_frame: None ,
412- cursor: None ,
416+ wal_frame: String :: new ( ) ,
417+ cursor: String :: new ( ) ,
413418 } ,
414419 ] ;
415420 let mut per_table: HashMap < String , TableBatch > = HashMap :: new ( ) ;
0 commit comments