Closed knife-s closed 6 years ago
As there is nothing unusual about tinydb's data file format, your question is equivalent to asking whether PHP can be used to read and write JSON files. The answer is "Yes."
Here's a link to get you started: https://www.taniarascia.com/how-to-use-json-data-with-php-or-javascript/
If you need more help with learning to use PHP to read/write JSON, you may want to look elsewhere, in PHP-focused venues, since tinydb is a Python-centric project.
Hope this helps!
Like @therden said it is possible to modify the file in PHP since it is just a JSON file, but updating it every x seconds smells like a recipe for concurrency issues. If you need to share the data between different processes you'll need file locks or atomic file IO (e.g. only renaming a temporary file and never modifying the file in place).
I know it is possible to modify the json file directly from php but the problem is.. what happens if while I am editing the json file from php the python script updates the data in the json file?.
How tinydb from python updates the data everytime we use .update() ? it updates an specific sector or the whole file all the time? isn't this risky?
Thank you in advance
It doesn't sound like TinyDB fits your use case.
Please see the Introduction in the documentation: "Why Not Use TinyDB?".
How tinydb from python updates the data everytime we use .update() ? it updates an specific sector or the whole file all the time? isn't this risky?
Yes, the JSONStorage of TinyDB always reads and writes the whole file. As @eugene-eeo mentioned, you could first write to a temporary file and then rename it to the file TinyDB uses for atomicity.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Feel free to reopen this if needed. Thank you for your contributions :heart:
Hello I was wondering if it is possible to manipulate the tinydb's json file in real time with php. (My json file gets updated every five seconds from a python script).
I would like to create something like phpmyadmin (but a basic version) for tinydb.
Or is there other way to manipulate the json file ? an existent software or something
Thank you