![]() JSON in a database isn't a bad practice per se, but I recommend only using it when you have data where your keys change, i.e. MyTable.create(my_data=xx_my_variable_xx) get dataĭata = _by(my_data=xx_my_variable_xx).first().my_data If you have more columns, just use more kwargs Import db from wherever, and copy the CRUDMixin and Model class from this sample codeįrom XX import MyTable create with your data. Id = db.Column(db.Integer, primary_key=True) If it's something simple enough that you can use JSON, I doubt you need to worry about database relationships! It could be as simple as this: Try that with a JSON file that is hundreds of MB large. It will also have no problem showing you data from a database with millions of rows (by pagenating the data). This allows you personally to view, filter, sort etc the data as if it’s an excel sheet - your data becomes human readable. One last addition is that you can use a program like DBeaver to view your sql data for SQLite and all other database types (I highly recommend it for anyone not familiar, it’s amazing). This is probably a better solution than keeping a single large JSON file anyway, or even dozens of smaller files. ![]() To boot, it’s going to be faster, easier to use, thoroughly tested, and more reliable than your code to parse JSON.Īt the end of the day, remember that you can put JSON into a database row if you want to keep your structure for the most part. However, somebody has already written the code to do what you want with SQLAlchemy. In short, you could probably do what you want in JSON just fine. If you’re reading and writing to JSON files, it’s possible, but writing your own interface would be cumbersome. To filter select items by attr1 and change attr2 for all of them. write will fail if columnX is blank)įor example, using a model with the CRUDMixin, all you have to do is something like: Database.filter(attr1=my_var).update(attr2=“bananas”) Easy to implement strict criteria on your data (e.g. Things like autoincrementing IDs and default values are easy to implement Better storage space optimization (many times) ACID compliance (look into that, it’s a necessity for high performance servers) Better handling of multiple reads/writes However, there are many many areas where a database excels. If you’re just doing a one-off store sort of thing, it’s probably not too bad to just use JSON. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |