msiemens / tinydb

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

Get Multiple Documents through get method of Table #504

Closed keenborder786 closed 1 year ago

keenborder786 commented 1 year ago

The feature augmentation in the table class is as per the requirement of #486. The user can now query multiple documents by specifying multiple doc_ids in form of a list in the get method of the Table class:

from tinydb import TinyDB, Query
db = TinyDB('/path/to/db.json')
db.insert({'int': 1, 'char': 'a'})
db.insert({'int': 1, 'char': 'b'})
db.get(doc_ids = [1,2]) # will return both the documents in form of list
keenborder786 commented 1 year ago

Any updates?

msiemens commented 1 year ago

Hey @keenborder786, sorry for not answering for so long! I was quite busy with work lately.

All in all, this looks quite good, my only suggestion would be to not reuse the doc_id parameter but instead use another doc_ids parameter just like you mentioned in your PR description. This way using doc_id will not break when users use a document ID class other than int 🙂 Could you adapt your code in this manner?

keenborder786 commented 1 year ago

sure. I will have a look.

keenborder786 commented 1 year ago

@msiemens can you please see now?

msiemens commented 1 year ago

Thanks for your contribution @keenborder786!

msiemens commented 1 year ago

I'll try to prepare a release of TinyDB with this feature sometime in the next two weeks

msiemens commented 1 year ago

Hey! I've now release TinyDB 4.8.0 that includes this feature 🙂