简体   繁体   中英

save retrieved data into a local json database using javascript

Hello can someone help me pls I want to retrieve data from a server database to an application via json, I don't have any problems with the server, and have token the data into the app, but I want to save this data into the local database (another json file which is database)by using javascript. Thanks

好吧,考虑到它只是json,而您想将其保存在本地,则可以将其另存为.json文件在磁盘上的某个位置,也许使用诸如fs之类的东西

You can use LocalStorage or SessionStorage to store your data in key value pairs.

If you want something more advanced I can recommend using localStorageDb wich is a database layer for those two.

An example:

var db = new localStorageDB("myDb", localStorage);
db.createTable("Persons", ["name", "surName", "birthDate"]);
db.insert("Persons", {name: "John", surName: "Doe", birthDate: new Date()});
db.commit()

Amplify.js will serve too with the advantage of being persistence agnostic, that is if LocalStorage is not supported it will fallback to another mechanism to store your data but lacks the database functionality.

If your database is large enough you should use IndexedDb or Web SQL. the main problem here beign compatibility. Check http://caniuse.com/indexeddb and http://caniuse.com/sql-storage

You can use this library https://github.com/yathit/ydn-db , it has support for schema generation, transactions, query support and client-server syncronization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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