Architecture Query Engine - osama1998H/Moca GitHub Wiki
Query Engine
Dynamic QueryBuilder, 15 operators, JSONB transparency, link auto-joins, and pagination.
The Query Engine provides a dynamic, type-safe query builder for constructing PostgreSQL queries from MetaType definitions.
QueryBuilder
Build queries programmatically with filters, sorting, pagination, field selection, and grouping.
15 Filter Operators
| Operator | SQL | Example |
|---|---|---|
= |
= |
status = 'Open' |
!= |
!= |
status != 'Closed' |
> |
> |
amount > 1000 |
< |
< |
amount < 5000 |
>= |
>= |
age >= 18 |
<= |
<= |
age <= 65 |
like |
LIKE |
name like '%john%' |
not like |
NOT LIKE |
email not like '%spam%' |
in |
IN |
status in ('Open', 'Pending') |
not in |
NOT IN |
role not in ('Guest') |
between |
BETWEEN |
date between '2025-01-01' AND '2025-12-31' |
is null |
IS NULL |
deleted_at is null |
is not null |
IS NOT NULL |
assigned_to is not null |
@> |
@> (JSONB) |
JSONB containment |
@@ |
@@ |
Full-text search |
JSONB Transparency
Fields stored in the _extra JSONB column are queried transparently -- the query builder automatically routes to _extra->>'field_name' when the field isn't a physical column.
Link Auto-Joins
When querying fields from a linked document (e.g., customer.customer_name), the query builder automatically generates LEFT JOIN clauses.
Reports
Two report types are supported:
- QueryReport -- SQL-based with parameterized filters
- ScriptReport -- Go function that returns tabular data