3/13/2023 0 Comments Rust sqliteThese are some of the sqlite sync strategies which you can use in diverse scenarios. If I know about LiteStream before, there was no need to throw my own custom logic to sync sqlite databases for my payroll project. In majority of cases this should be your first choice for sqlite replication due to its simplicity. A complete documentation of LiteStream is available on its website. The beauty of LiteStream is, it continously stream changes to cloud servers or network file system. LiteStream is a tool which caught my attention few months ago and its surprisingly pleasant experience to use it. Realtime Sqlite Replication With LiteStream A detailed tutorial of this tool is available sqlite-rdiff github repo. As I always say you should try out this tool yourself to find out whether it fits your use case or not. I haven’t used this tool in production yet. It syncs local sqlite database with remote database without much fuss. The above sync strategy is very naive, its fragile and can break easily due to myriad reasons. SQLite master-slave replication with sqlite3-rdiff Table2.update(dict(last_sync_id=last_id,id=0),) # This function simply add data in Payroll Sytstemĭef update_payroll_data(result_list,last_id): Update_payroll = update_payroll_data(gate_data,last_id) # If some data received add data in payroll and save the last row id of GateSystem Gate_data = ('fetch_gate_entry_data',last_synced_id) Query = f"SELECT * from (select * from Attendance WHERE id > ") # This function receives id as argument which is basically last_synced_idįrom payroll and return the data to fetch_gate_entry_data(id:int): Query = f"SELECT id from Attendance order by id DESC LIMIT 1" With nnect('sqlite:///database//mydatabase.sqlite') as tmp: # Step1: Fetch ID of last row from GateEntry fetch_last_id(): Payroll System can remotely call these functions via Anvil Uplink. ![]() Otherwise your databases can go out of sync any moment due to lost network connection or any database related error. You have to make sure that, whenever you sync, the data and last row id of source table should be saved in a single transaction in destination database. Basically whenever I sync data I save the Attendance Tables’s last row ID in Payroll System. I have created a table in Payroll System called LastSync with two columns “id” and “last_sync_id” to save the last row ID of Attendance Table from Gate Entry System. I am using “last_synced_id” from source (Gate Entry System) to keep both sets of tables in sync. You can read more about Anvil Framework here. Anvil Uplink is part of anvil framework which makes it super easy to remotely call python code running on any computer. For my particular case I have to sync “ Attendance table” from GateEntry System with “ GateEntry table” in Payroll System.īoth Systems are running on separate computers and connected to each other via Anvil Uplink. One of the requirement was to synchronize payroll database with client’s GateEntry System which is using sqlite database (One way Synchronization).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |