NocoDB Module API Explanation
The NocoDB module tracks data records count and daily database transaction logs.
API Execution Logic
Rather than querying a single base, the NocoDB module is configured to process multiple tables. It parses the base URL and loads the NOCODB_API_KEY to authenticate requests.
Request Headers and Time Parameters
Requests use the xc-token header to authenticate. To calculate "today's transactions," the module determines the time boundaries:
- Time Boundaries: It calculates the start of today (00:00:00) and start of tomorrow (00:00:00 of the next day) in UTC.
- Format Conversion: The dates are converted to ISO strings formatted as
YYYY-MM-DD HH:mm:ssto match NocoDB requirements.
Multi-Table Query Execution
For each table declared under the nocodb.tables config, two API requests are sent in parallel via Promise.all:
- Total Count Query: A GET request is sent to
/api/v2/tables/[TABLE_ID]/records/count. - Today's Count Query: A GET request is sent to the same endpoint, adding a query filter parameter:
where=(created_at,gte,exactDate,[START_TIME])~and(created_at,lt,exactDate,[END_TIME]). (The target column defaults tocreated_atbut can be overridden viadateField).
Aggregation
The module aggregates results across all tables:
- Primary Metric: The sum of today's records count.
- Secondary Metric: The total sum of all records in the tables.
If any table query fails, the failed table is marked as offline, but the module returns the aggregated totals for the successful tables.