Counting records

You can count the number of rows in any select query:

  1. >>> Tweet.select().count()
  2. 100
  3. >>> Tweet.select().where(Tweet.id > 50).count()
  4. 50

Peewee will wrap your query in an outer query that performs a count, which results in SQL like:

  1. SELECT COUNT(1) FROM ( ... your query ... );