F
F
Flaca Strexy2020-11-22 19:47:31
Python
Flaca Strexy, 2020-11-22 19:47:31

Can a dictionary be used instead of a full database?

Hello. I am making a telegram bot in python for registering and recording clients (and this is not particularly important), there is also another bot, a game one. The database in the game bot is made using a dictionary , and the Json library saves it to a .json file , and also receives the database from it back to the dictionary . The question is what can go wrong if you use this method, it is convenient for me. And there is simply no time to deal with SQL yet, and I don’t really want to, I tried sqlite3 , very complex queries, on pure sql
, although I just need to store dates, and check if they are busy, and if they are busy, then store information about the client there (another dictionary ). In general, does it make sense to install some kind of database like sqlite3 , MySql , or can you get by with a dictionary ? It’s just that there are fears that it will become very inflated over time, and won’t it be hard for json ? I plan to delete old days, etc., but still, I want to ask knowledgeable people if it is possible to do this. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-11-22
@flacastrexy

It depends on what content is in the json file. If it is small, and the project is just a small pet project, then you can get by with a file. Especially if the work does not involve a large number of calls.

what could go wrong

1. File lock. While reading, the file is locked and inaccessible to other threads. In principle, if the file size is small and the number of accesses is small, then the chance that two threads will try to access the file at the same time is very, very small, almost impossible, I would say. If you use the same sqlite3, then you need to know that it also blocks access during operation.
2. Data loss. If you read a file, copy the content from it into some variable, then another thread will do the same. The first thread will add client X to json and dump it into a file. The second thread will add client Y and dump it into the file, while taking into account that the second thread has old content (before adding client X), when dumping, there will no longer be any client X in the file, only Y.
If you learn to work with databases, it is better to choose a normal one, like postgresql, then there will be no problems. sqlite3 - a frivolous option, something between a regular tektovik and a database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question