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

feat: add query result limit #508

Closed NafieAlhilaly closed 10 months ago

NafieAlhilaly commented 1 year ago

🖐😃

509

changes

Add limit option to db.all() and db.search() to limit the query result. this will also limit cached query result


example

from tinydb import TinyDB, where

db = TinyDB("local.json")

# insert some data
for i in enumerate(range(0, 20)):
    db.insert({
        "id": i,
        "name": "awesome name"
    })

db.all()  # 20
db.all(limit=9)  # 9

ldb.search(where("id") > 1 and where("id") > 10)  # 9
db.search(where("id") > 1 and where("id") > 10, limit=3)  # 3