···180180 // TODO: Handle primary key conflict, for now reject it (in a way its impossible to have this scenario, and if its occuring then that means
181181 // some issue in syncing, so ignore it, by rejecting it), later
182182 // do LWW based on issuer of UCAN
183183+ //
184184+183185 let txn = chat_conn.transaction()?;
184186 {
185187 let mut stmt = txn.prepare("insert into chats(id, user_id, content, resp_id, role, context_id, created_at, updated_at, row_counter) values (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)")?;
···204206 &chat.id
205207 );
206208 }
207207- Err(err) => log::error!("err in writing row due to {:?}", err),
209209+ // NOTE: If any other error occurs and write failed we abort the sync, so the the row_counter doesn't get skipped.
210210+ // use RUST_LOG=error tiles to debug the issue
211211+ Err(err) => {
212212+ log::error!(
213213+ "err in writing row due to {:?}, Aborting the sync ....",
214214+ err
215215+ );
216216+ break;
217217+ }
218218+208219 Ok(_) => (),
209220 }
210221 }
+1-4
tiles/src/core/mod.rs
···5566use anyhow::Result;
7788-use crate::core::{
99- accounts::save_root_account_db,
1010- storage::db::{Dbconn, init_db},
1111-};
88+use crate::core::{accounts::save_root_account_db, storage::db::Dbconn};
1291310pub mod accounts;
1411pub mod chats;
+5-5
tiles/src/main.rs
···55use clap::{Args, Parser, Subcommand};
66use tiles::{
77 core::{
88- self, init,
88+ self,
99 network::{link, sync},
1010 storage::db::init_db,
1111 },
···213213 core::init(&db_conn)
214214 .inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?;
215215 if !cli.flags.no_repl {
216216- commands::run(&runtime, run_args)
216216+ commands::run(&runtime, run_args, &db_conn)
217217 .await
218218 .inspect_err(|e| eprintln!("Tiles failed to run due to {:?}", e))?;
219219 }
···229229 };
230230 core::init(&db_conn)
231231 .inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?;
232232- commands::run(&runtime, run_args)
232232+ commands::run(&runtime, run_args, &db_conn)
233233 .await
234234 .inspect_err(|e| eprintln!("Tiles failed to run due to {:?}", e))?;
235235 }
···275275 },
276276 Some(Commands::Link(link_args)) => match link_args.command {
277277 LinkCommands::Enable { ticket } => link(ticket).await?,
278278- LinkCommands::Disable { did } => unlink_peer(&did)?,
278278+ LinkCommands::Disable { did } => unlink_peer(&db_conn, &did)?,
279279 LinkCommands::ListPeers => {
280280- show_peers()?;
280280+ show_peers(&db_conn)?;
281281 }
282282 },
283283 Some(Commands::Sync { did }) => sync(did).await?,