pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.76k stars 297 forks source link

How to retrieve the count of records from .all() #350

Closed faridanthony closed 3 years ago

faridanthony commented 3 years ago

records = self.db['users'].all()

I have tried: len(records) records.count() records.rowcount

<class 'TypeError'>: object of type 'ResultIter' has no len() AttributeError: 'ResultIter' object has no attribute 'count()' AttributeError: 'ResultIter' object has no attribute 'count'

to no avail. I'm using this to populate a table and I need to be able to set the number of rows based on the number of records retrieved in my query. Thanks!

pudo commented 3 years ago

If I'm understanding you correctly, len(self.db['users']) should do the trick :)

DataGreed commented 3 years ago

@pudo is there a way to retrieve the number of records filtered by find()? len() does not work for this case, raising a TypeError: object of type 'ResultIter' has no len()

DataGreed commented 3 years ago

Oh, okay, you have to use table.count(**filter_clause) to get it.