4 ms·
Regarding your first point, even simpler could be to store the json as string in sqlite as to avoid all the file handling stuff, but I would say that sqlite is
by Scarbutt 8y ago
Regarding your first point, even simpler could be to store the json as string in sqlite as to avoid all the file handling stuff, but I would say that sqlite is already a popular solid application format ;)
- int_19h 8y agoBut the only file handling stuff you need to load JSON from a file is to open the file. And if it's in SQLite, then you'll need to open the database and query - more complicated, no?
- Scarbutt 8y agoI think is more complex than that, when you modify some data structure in memory you also want write to disk immediately as to not lose any data in case of a crash, so this means to write the new file under a separate name and then renaming the new file to replace the old file only after it has been successfully written as to provide safety against storage corruption. I wouldn't recommend this to a beginner, the sqlite driver(of your language) would handle all this for you in a safe way.
- int_19h 8y ago> this means to write the new file under a separate name and then renaming the new file to replace the old file only after it has been successfully written as to provide safety against storage corruption I agree, that's about the only bit of complexity in all this. But it's completely generic, so it can be made into a small library, and then reused without dealing with the complexity every time. For example: https://www.npmjs.com/package/write-file-atomic https://www.npmjs.com/package/write-file-atomic
- kevin_thibedeau 8y agoOpen the file, parse its content, deal with any errors. SQLite is simpler.
- int_19h 8y agoOpening the file and parsing JSON in it is two lines of code in Python. Errors can happen in both cases - you can have a corrupt SQLite DB, just as you can have invalid JSON. The way you handle them is pretty much identical.