Count — how many rows match, without loading them

db.count(entity, opts) returns just the number of matching rows. Use it for pagination totals, badge counts, and quick checks where you don't need the data itself. Same filter vocabulary as list.

How it works

flowchart LR
    A["count(entity, opts)"] --> I{index
available?} I -- yes --> IX[Index scan] --> N[count] I -- no --> DS[Data scan] --> N B["list(entity, opts)"] --> DS2[Data scan] --> Arr[array of rows] --> L["arr.length"] L -. should equal .- N style N fill:#c8e6c9,stroke:#2e7d32 style L fill:#fff3e0,stroke:#ef6c00

Try it — a four-step tour

  1. Click Seed 50 products. Products have a random price and a category chosen round-robin from 5 categories (so 10 electronics, 10 books, etc.).
  2. Click Count all — reads 50.
  3. Click Count (price > 50) and Count (electronics) — the counter updates with the filtered count and the label explains what was counted.
  4. Click Verify count vs list — runs both queries and shows that count(opts) and list(opts).length agree.

Setup

Seed data

50 products with random price (0–100) and a category cycling through electronics, books, clothing, food, toys (10 of each).

Entity

Count result

0

Custom filter

Build any filter and see its count. Value can be a string, a number (auto-detected), true/false, or empty for null operators.

Count vs list verification

Confirms that count(opts) and list(opts).length always agree for the same options.

Automated test suite

Run all tests seeds 50 rows into count_test and runs these 6 checks:

  1. Unfiltered count returns 50
  2. count(price > 50) matches list(...) length
  3. count(category = "electronics") returns 10 (seed is deterministic)
  4. Multi-filter (price > 20 AND category = "books") matches list length
  5. countSync returns the same number as count
  6. count on an empty entity returns 0
Click the button to run.

Log