aboutsummaryrefslogtreecommitdiff
path: root/query/count.md
diff options
context:
space:
mode:
Diffstat (limited to 'query/count.md')
-rw-r--r--query/count.md48
1 files changed, 48 insertions, 0 deletions
diff --git a/query/count.md b/query/count.md
new file mode 100644
index 0000000..bb4e14d
--- /dev/null
+++ b/query/count.md
@@ -0,0 +1,48 @@
+# Count
+
+[back to query](README.md) /// [home](../README.md)
+
+Count rows matching a filter. Like select but just gives you the number in data field.
+
+## Request
+
+```json
+{
+ "action": "count",
+ "table": "items",
+ "filter": {
+ "column": "status",
+ "op": "=",
+ "value": "active"
+ }
+}
+```
+
+## Fields
+
+| Field | Type | Required | Notes |
+|----------|--------|----------|-----------------------------|
+| `action` | string | yes | must be `"count"` |
+| `table` | string | yes | target table |
+| `where` | object | no | simple key value filter |
+| `filter` | object | no | structured filter |
+| `joins` | array | no | join other tables if needed |
+
+No limit or offset for count, it always counts everything that matches.
+
+## Response
+
+```json
+{
+ "success": true,
+ "data": 42
+}
+```
+
+`data` is just the count as a number.
+
+## Behaviors
+
+- should support joins so you can count rows with conditions on related tables
+- ownership scoping should apply: if you have `rwo` or `rwg` the count should only include rows you have access to
+- you need at least read permission on the table