I wanted to develop a simple Android app that requires a small database. I've developed a prototype with App Inventor and TinyDB, but it seems that TinyDB allows to add several records to the database with the same "tag" (this is how keys are named in TinyDB).
I am adding an extra field that autoincrements itself in every database record and using this counter as a primary key, but that's not exactly what I want. Is there a way to implement a primary key constraint for a "tag" in TinyDB?
TinyDB has no built-in way to store primary keys, but you can store an ordered list of the items where the index is the primary key. Then you just find where it is in the list to find the primary key.
If you use that system, though, you will decrease the keyspace (there will be one less possible tag out of an infinite number of possible tags that can be stored by the user.) If the user gets to create their own tags, you can prefix all of the tags they create with a symbol. No matter what tags the user enters, they will not be able to accidentally or purposely overwrite your primary key list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With