Count¶
Answers how many rows match find, without reading them.
In short
POST /api/schema/<user-path>/<instance>/<database>/<table>/count- Body :
{ "find": {…} }.{ "find": {} }counts the whole table. datais the number.
| Method | POST |
| URL | /api/schema/admin/mysql8/inventory/customers/count |
| Body | { find } |
| Query params | none |
| Answer | data : the number of rows |
| Databases | MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server, Oracle, TiDB, Percona |
| Cached | yes, when enableCaching is on for the table or the database |
| From code | g.sys.db.count |
| API id | SCHEMA_POST_COUNT |
| Without a schema | /api/gen/admin/mysql8/inventory/customers/count : below |
The examples count the table of get all.
The call¶
find takes every operator of find, and the keys of related tables :
The orders of gold customers : orders.customer_id refers to customers
{ "find": { "customer_id.loyalty_tier": "GOLD" } }
Good to know¶
- Types. The values take the types of the schema :
"pincode": "382345"counts the number 382345. - No related row. When a filter on a related table matches no row there,
datais an empty list[], not0. - A list and its total in one call : query with
getTotalCount: true. - Cache. With caching on, the count answers from Redis until a write changes the table.
From your code¶
g.sys.db.count makes the same call from custom APIs, hooks, events, schedulers and test cases.
Without a schema : /api/gen¶
Every table also answers this operation under /api/gen, with or without a schema :
| URL | /api/gen/admin/mysql8/inventory/customers/count |
| API id | GEN_POST_COUNT |
| From code | g.sys.db.gen.countGen |
find matches the type you send : "22" does not match the number 22. On MongoDB, a text that looks like an ObjectId is turned into one.
Headers and errors¶
This operation takes the request headers of every API. It answers the envelope, with the status codes and the messages of every API.
Related : All APIs · Table schema · Pre hooks · Post hooks · API group permission