Skip to content

DB Count ​

The DB Count block counts the records in a table that match your conditions and passes on that number. Use it for "how many active orders does this rider have?", or to show a total next to a paginated list, without loading every row.

When to use it ​

  • Show a total next to a list, like "128 results".
  • Check a limit before you allow something, like "fewer than 5 open tickets".
  • Don't use it just to know whether something exists. DB Row Exists is built for that.
  • Don't use it when you need the records too. DB Get All gives you the list, and its length.

Inputs ​

The same fields as DB Get Single, without Columns.

FieldRequiredDefaultWhat it does
ConnectionYesnoneThe database integration to use.
Table NameYesnoneThe table (or collection) to count in.
ConditionsNonone (every record)Rules that pick the records to count, see DB Conditions. A condition whose value is undefined is skipped.
JoinsNononeOther tables to combine, SQL only. See DB Joins.
Save output to variableNooffStore the number in outputs.<name>.

Outputs ​

HandleWhen it is used
Next (right)The count worked. The next block receives a number, for example 3. It is 0 when nothing matches.

Example ​

How many active orders does rider 7 have?

FieldValue
Connectionmain-db
Table Nameorders
Conditionsrider_id = 7 AND status = active

The next block receives 3. Use it in a Response body or an If Condition.

How it behaves ​

  • No conditions counts every record in the table.
  • With joins, each joined row counts once. A user with two orders counts twice when you join orders.
  • MongoDB: joins are skipped. To combine collections, use a DB Native block.
  • A missing table: on MongoDB, a collection that doesn't exist counts as 0. On PostgreSQL and MySQL, a missing table is an error.
  • Database errors (bad connection, missing table or column) go to the Error Handler.
  • It replaces the flowing data with the number.

Released under the Apache License 2.0. Enterprise features are under the Fluxify Enterprise Edition License.