msiemens / tinydb

TinyDB is a lightweight document oriented database optimized for your happiness :)
https://tinydb.readthedocs.org
MIT License
6.76k stars 534 forks source link

How can we ensure uniqeness when inserting #553

Closed fenchu closed 7 hours ago

fenchu commented 8 months ago

Since the tinydb is an array of loglines, how can I ensure uniquness on those loglines,

Currently each logline is an hash with my unique id, so I need to add it to a hash and then save it back again. this takes time. Especially when the structure grow.

Would be nice if we could set like max1000 lines and use my id as the identifier.

I do not have this problem when app runs singlethreaded. But has become a pain not lots of people using it.

A91y commented 6 months ago

I think tinydb is not designed to handle multiple request at the same time. It's clearly stated in the documentation itself.

image
msiemens commented 7 hours ago

Hey @fenchu, as @A91y has pointed out, TinyDB is not designed for concurrent/multithreaded usage. Futhermore, there is no mechanism for specifying uniqueness constraints in TinyDB and it is a feature TinyDB wasn't really designed for. So, simply said, it seems to me that TinyDB doesn't work out for your use case. Maybe you could investiagte using Sqlite as it is a more fully-featured database system.