Closed NGenetzky closed 6 years ago
Thanks for creating a great python package. I am excited to use it in my current project.
Hey, you can pass your own parameters to JSONStorage
which are passed down to dumps
. So you can use this to get a formatted JSON file:
db = TinyDB('db.json', sort_keys=True, indent=4, separators=(',', ': '))
(Just for reference: this has been implemented in #61)
Feel free to re-open if it doesn't work as expected.
This is wonderful. Please include a mention of these options in the docs? Could mention it on getting-started.html or in API doc - database
Hi @msiemens , this code is working well, but in sorting since the id's are as strings, it is sorting them as string. So, they are coming in this order : 1, 10, 100, 102, ... 179, 18, 180, ... 199, 2, 20, 200... . This is not much problem from operations point of view so I'm ok with it, but wanted to share FYI.
This is wonderful. Please include a mention of these options in the docs? Could mention it on getting-started.html or in API doc - database
I've added this to the docs in 0ae404967d7dc467a3dad40d2481a87a598fd9ce 🙃
Sorry if this is a silly question, but I was wondering, it doesn't seem like there would be, but is there any sort of performance impact that might come down the road if the database starts to get sizable when using the formatted version due to all the extra whitespace?
@MostHated , Yes extra processing (formatting) will most certainly affect performance. If that starts to be a concern I would recommend you leave the default separators and simply do the formatting as a separate script/aciton.
I currently find my self using a simple function to prettify the json database before I commit it to a git repository. I do this for two reasons: 1. readability 2. diff-ability .
Is there currently a built in way to do this? I didn't see anything on the 'TinyDB' class. Would you consider adding a small function that makes it easier?
I also took a glance at 'storage.py' and it appears that it would be pretty easy to utilize the
self.kwargs
ofJSONStorage
to usedumps(data, sort_keys=True, indent='\t')
. Do you think that this would cause a major performance hit?