简体   繁体   English

React Native - 本地存储(sqlite)与实时服务器同步

[英]React Native - Local storage (sqlite) sync with live server

The concept of my app is a basic survey collector excel sheet with 500 input fields/check boxes for each company registered, divided into 5 sections/screens on the mobile (each with 100 input fields).我的应用程序的概念是一个基本的调查收集器 excel 表,每个注册公司有 500 个输入字段/复选框,在移动设备上分为 5 个部分/屏幕(每个有 100 个输入字段)。 Every screen has a save button.每个屏幕都有一个保存按钮。 Upon clicking the save button, the data should be saved in sqlite (offline/local db) and live server as well.单击保存按钮后,数据应保存在 sqlite(离线/本地数据库)和实时服务器中。 And if the internet connection is unstable or not available only the data should be saved in local db.如果互联网连接不稳定或不可用,则只应将数据保存在本地数据库中。 Till this I am done.到此为止我已经完成了。 My question is that when the internet is available how will I sync the saved data which is in my local db?我的问题是,当互联网可用时,我将如何同步本地数据库中保存的数据? And how will I maintain the flag which will indicate which screens are synced?我将如何维护指示哪些屏幕已同步的标志?

For instance I am shown a list of companies and I select one among them and fill 2 of it's screens online and rest 3 offline.例如,我看到了一个公司列表,我从其中选择一个并在线填写其中的 2 个屏幕,离线填写 3 个。 Then I click another company and save it's random 2 screens offline as well.然后我点击另一家公司并离线保存它的随机 2 个屏幕。 The internet is available then.那时就可以上网了。 Now how will I sync my those 2 and first 3 screens?现在我将如何同步我的那 2 个和前 3 个屏幕?

What you are asking is all about designing your local database.您要问的是关于设计本地数据库的全部内容。 If you are sending data to your server for each screen separately, You can have a new column dedicated for the synced_flag.如果您为每个屏幕分别向服务器发送数据,您可以有一个专用于 synced_flag 的新列。

Screen1 => true屏幕 1 => 真
Screen2 => false屏幕 2 => 假

If you want to track your internet connection in real-time, You can use the NetInfo package for this kind of thing.如果你想实时跟踪你的互联网连接,你可以使用NetInfo来做这种事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM