Craticula

Migrating from OData

This page is for a team whose grid talks to an OData service today and wants to move to Craticula. It shows, construct by construct, what you wrote in OData and the request Craticula takes instead. Every example is a file that a test compiles, so the request and the statement under it are real and cannot go stale.

Two things are different from the start:

All examples use one small synthetic schema, orders (id, customer, amount, active, status, region, country), and print the PostgreSQL statement. The other databases get their own spelling of the same request.

{
  "mode": "strict",
  "source": "orders",
  "stableKey": "id",
  "fields": {
    "id": {
      "type": "int64",
      "sortable": true,
      "physical": {
        "sql": {
          "column": "id"
        }
      },
      "aggregatable": [
        "count"
      ]
    },
    "customer": {
      "type": "string",
      "filterable": true,
      "sortable": true,
      "physical": {
        "sql": {
          "column": "customer"
        }
      }
    },
    "amount": {
      "type": "decimal",
      "filterable": true,
      "sortable": true,
      "aggregatable": [
        "sum",
        "avg",
        "min",
        "max",
        "count"
      ],
      "physical": {
        "sql": {
          "column": "amount"
        }
      }
    },
    "active": {
      "type": "boolean",
      "filterable": true,
      "sortable": true,
      "physical": {
        "sql": {
          "column": "active"
        }
      }
    },
    "status": {
      "type": "string",
      "filterable": true,
      "sortable": true,
      "physical": {
        "sql": {
          "column": "status"
        }
      }
    },
    "region": {
      "type": "string",
      "filterable": true,
      "sortable": true,
      "physical": {
        "sql": {
          "column": "region"
        }
      },
      "groupable": true
    },
    "country": {
      "type": "string",
      "filterable": true,
      "sortable": true,
      "groupable": true,
      "physical": {
        "sql": {
          "column": "country"
        }
      }
    }
  }
}

$filter #

A comparison on one column #

OData: $filter=status eq 'active'. The same holds for ne, gt, ge, lt, le: they become the filter types equals, notEqual, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "status": {
      "filterType": "text",
      "type": "equals",
      "filter": "active"
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE "status" COLLATE craticula_ci = $1 ORDER BY "id" ASC NULLS LAST LIMIT $2 OFFSET $3
-- parameters: 'active', 100, 0

The comparison is COLLATE craticula_ci: text compares case-insensitively by default (Case sensitivity). In OData the result usually depends on the service and its database. If your users relied on exact case, declare the field caseSensitivity: "sensitive" in the schema.

contains, startswith, endswith, and and across columns #

OData: $filter=contains(customer,'acme') and amount gt 100. The text functions are the filter types contains, startsWith and endsWith; notContains is the only negation the grid's text filter has. Filters on different columns are joined with AND, one filterModel entry per column.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "customer": {
      "filterType": "text",
      "type": "contains",
      "filter": "acme"
    },
    "amount": {
      "filterType": "number",
      "type": "greaterThan",
      "filter": 100
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE ("customer" ILIKE '%' || $1 || '%' ESCAPE '\' AND "amount" > $2::numeric) ORDER BY "id" ASC NULLS LAST LIMIT $3 OFFSET $4
-- parameters: 'acme', '100', 100, 0

The contains match is escaped: the user's % and _ are literal characters, never wildcards (Substring matching on OpenSearch).

or on one column #

OData: $filter=amount gt 100 or amount lt 10. Two conditions on the same column go in the column's conditions array with operator: "OR" (or "AND").

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "amount": {
      "filterType": "number",
      "operator": "OR",
      "conditions": [
        {
          "filterType": "number",
          "type": "greaterThan",
          "filter": 100
        },
        {
          "filterType": "number",
          "type": "lessThan",
          "filter": 10
        }
      ]
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE ("amount" > $1::numeric OR "amount" < $2::numeric) ORDER BY "id" ASC NULLS LAST LIMIT $3 OFFSET $4
-- parameters: '100', '10', 100, 0

in #

OData (4.01): $filter=status in ('active','pending'). This is the grid's set filter.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "status": {
      "filterType": "set",
      "values": [
        "active",
        "pending"
      ]
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE "status" COLLATE craticula_ci = ANY($1) ORDER BY "id" ASC NULLS LAST LIMIT $2 OFFSET $3
-- parameters: ['active', 'pending'], 100, 0

ne and not #

OData: $filter=status ne 'blocked' or $filter=not (status eq 'blocked'). In the grid this is the notEqual filter type.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "status": {
      "filterType": "text",
      "type": "notEqual",
      "filter": "blocked"
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE ("status" COLLATE craticula_ci <> $1 OR "status" IS NULL) ORDER BY "id" ASC NULLS LAST LIMIT $2 OFFSET $3
-- parameters: 'blocked', 100, 0

Read the statement closely. status ne 'blocked' also returns the rows where status is NULL. Craticula's negative operators include null rows on purpose (Null handling), so the grid behaves like AG Grid's own in-memory filter. SQL's three-valued logic would drop those rows, and an OData service may or may not. Check the old behaviour with a test before you migrate a filter that excludes values.

eq null and ne null #

OData: $filter=region eq null. There are two forms, and they differ for text columns.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "region": {
      "filterType": "text",
      "type": "blank"
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE ("region" IS NULL OR "region" = '') ORDER BY "id" ASC NULLS LAST LIMIT $1 OFFSET $2
-- parameters: 100, 0
{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {},
  "sortModel": [],
  "customFilters": {
    "type": "comparison",
    "field": "region",
    "op": "eq",
    "value": {
      "type": "null"
    }
  }
}
SELECT * FROM "orders" WHERE "region" IS NULL ORDER BY "id" ASC NULLS LAST LIMIT $1 OFFSET $2
-- parameters: 100, 0

ne null has no exact form on a text column. notBlank returns the rows that are neither null nor empty. Do not write neq with a null value (it returns only the null rows, as SQL's three-valued logic and SEM-2 combine) or not around the null test (it returns every row).

Ranges and booleans #

$filter=amount ge 10 and amount le 20 is two conditions on one column joined by AND.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "amount": {
      "filterType": "number",
      "operator": "AND",
      "conditions": [
        {
          "filterType": "number",
          "type": "greaterThanOrEqual",
          "filter": 10
        },
        {
          "filterType": "number",
          "type": "lessThanOrEqual",
          "filter": 20
        }
      ]
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE ("amount" >= $1::numeric AND "amount" <= $2::numeric) ORDER BY "id" ASC NULLS LAST LIMIT $3 OFFSET $4
-- parameters: '10', '20', 100, 0

The grid's own in-range option is refused because its two bounds carry no inclusivity; the customFilters extension has an inRange operator with the inclusivity written out. A boolean property, $filter=active eq true, is the set filter on a boolean column, which compiles to the true operator.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {
    "active": {
      "filterType": "set",
      "values": [
        "true"
      ]
    }
  },
  "sortModel": []
}
SELECT * FROM "orders" WHERE "active" = $1 ORDER BY "id" ASC NULLS LAST LIMIT $2 OFFSET $3
-- parameters: true, 100, 0

Dates and date-times #

A date filter takes the grid's wire form: yyyy-MM-dd, or yyyy-MM-dd HH:mm:ss as a wall-clock time read in the zone the request carries (requestContext.zone) or the parser options name, UTC by default (Dates and time zones). An OData literal such as 2026-01-01T00:00:00Z or one with an offset does not fit that form. Convert it to the request's zone, or send the exact instant through customFilters as a typed datetime value that names its zone.

Anything else: a tree of and, or, not #

AG Grid's filters cover one column at a time. For a nesting such as not startswith(customer,'test') and (status eq 'active' or amount gt 1000), Craticula accepts an extension next to filterModel: customFilters, a tree of and, or, not and comparison nodes over the closed set of 17 operators: eq, neq, gt, gte, lt, lte, contains, notContains, startsWith, endsWith, in, notIn, inRange, blank, notBlank, true, false. It is also where a negated startsWith or endsWith lives, because the grid has no such filter type. The tree is merged with filterModel by AND. Its depth and size are limited (the resource limits of SEC-3), so a huge $filter is refused instead of compiled.

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {},
  "sortModel": [],
  "customFilters": {
    "type": "and",
    "nodes": [
      {
        "type": "not",
        "node": {
          "type": "comparison",
          "field": "customer",
          "op": "startsWith",
          "value": {
            "type": "string",
            "value": "test"
          }
        }
      },
      {
        "type": "or",
        "nodes": [
          {
            "type": "comparison",
            "field": "status",
            "op": "eq",
            "value": {
              "type": "string",
              "value": "active"
            }
          },
          {
            "type": "comparison",
            "field": "amount",
            "op": "gt",
            "value": {
              "type": "decimal",
              "value": "1000"
            }
          }
        ]
      }
    ]
  }
}
SELECT * FROM "orders" WHERE ((NOT ("customer" ILIKE $1 || '%' ESCAPE '\') OR "customer" IS NULL) AND ("status" COLLATE craticula_ci = $2 OR "amount" > $3::numeric)) ORDER BY "id" ASC NULLS LAST LIMIT $4 OFFSET $5
-- parameters: 'test', 'active', '1000', 100, 0

$orderby, $top, $skip, $count #

OData: $orderby=amount desc,id&$top=20&$skip=40. $orderby is sortModel, first entry first. $skip is startRow and $skip + $top is endRow (exclusive), so $skip=40&$top=20 is startRow: 40, endRow: 60.

{
  "startRow": 40,
  "endRow": 60,
  "rowGroupCols": [],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {},
  "sortModel": [
    {
      "colId": "amount",
      "sort": "desc"
    },
    {
      "colId": "id",
      "sort": "asc"
    }
  ]
}
SELECT * FROM "orders" ORDER BY "amount" DESC NULLS FIRST, "id" ASC NULLS LAST LIMIT $1 OFFSET $2
-- parameters: 20, 40

Two differences:

$count=true (the @odata.count of the answer) is the row count the execution adapters return next to the page when you ask for it (includeRowCount: RowCount, and AG Grid's lastRow). On SQL and MongoDB it is a second query. On OpenSearch and Elasticsearch it is capped by default and reported as unknown above 10,000 rows (see index guidance).

$apply: groupby and aggregate #

OData: $apply=groupby((country),aggregate(amount with sum as total)). The grid's row grouping sends rowGroupCols (the group columns, outermost first), valueCols (the aggregates: sum, min, max, avg, count) and groupKeys (the groups the user has opened).

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [
    {
      "id": "country",
      "displayName": "Country",
      "field": "country"
    }
  ],
  "valueCols": [
    {
      "id": "amount",
      "displayName": "Amount",
      "field": "amount",
      "aggFunc": "sum"
    }
  ],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [],
  "filterModel": {},
  "sortModel": [
    {
      "colId": "country",
      "sort": "asc"
    }
  ]
}
SELECT "country" AS "country", COALESCE(SUM("amount"), 0) AS "amount_sum" FROM "orders" GROUP BY "country" ORDER BY "country" ASC NULLS LAST LIMIT $1 OFFSET $2
-- parameters: 100, 0

A request returns one level. With groupby((country,region)) the grid asks for the countries first. When the user opens Germany it sends the group key Germany and gets the regions of Germany:

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [
    {
      "id": "country",
      "displayName": "Country",
      "field": "country"
    },
    {
      "id": "region",
      "displayName": "Region",
      "field": "region"
    }
  ],
  "valueCols": [
    {
      "id": "amount",
      "displayName": "Amount",
      "field": "amount",
      "aggFunc": "sum"
    }
  ],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [
    {
      "type": "string",
      "value": "Germany"
    }
  ],
  "filterModel": {},
  "sortModel": [
    {
      "colId": "region",
      "sort": "asc"
    }
  ]
}
SELECT "region" AS "region", COALESCE(SUM("amount"), 0) AS "amount_sum" FROM "orders" WHERE "country" = $1 GROUP BY "region" ORDER BY "region" ASC NULLS LAST LIMIT $2 OFFSET $3
-- parameters: 'Germany', 100, 0

One level further, with both keys consumed, it gets the rows:

{
  "startRow": 0,
  "endRow": 100,
  "rowGroupCols": [
    {
      "id": "country",
      "displayName": "Country",
      "field": "country"
    },
    {
      "id": "region",
      "displayName": "Region",
      "field": "region"
    }
  ],
  "valueCols": [],
  "pivotCols": [],
  "pivotMode": false,
  "groupKeys": [
    {
      "type": "string",
      "value": "Germany"
    },
    {
      "type": "string",
      "value": "Bavaria"
    }
  ],
  "filterModel": {},
  "sortModel": [
    {
      "colId": "id",
      "sort": "asc"
    }
  ]
}
SELECT "id", "customer", "amount", "active", "status", "region", "country" FROM "orders" WHERE ("country" = $1 AND "region" = $2) ORDER BY "id" ASC NULLS LAST LIMIT $3 OFFSET $4
-- parameters: 'Germany', 'Bavaria', 100, 0

AG Grid's own request carries the keys as plain strings (groupKeys: ["Germany"]). The parser Craticula ships takes each key as a typed value ({"type": "string", "value": "Germany"}), so a small step in your frontend adapter types the keys from the column types before the request is parsed. The demo's toWireRequest (datasource.ts) is ten lines that do it, a null key included.

Differences to know:

What has no equivalent #

ODataWhy not, and what to do
$expand, navigation properties, $filter across a relationshipA schema reads one source (a table, a collection or an index) and every column is a field of it. Build a view or an index that joins the data and declare the view as the source.
$selectThe columns are the schema's. A request cannot ask for a subset of them, and the execution adapters return only the declared fields. With the bare compiler an ordinary row query is SELECT *, so a column you do not declare is still in the result: leave it out of the view you declare as the source. An export can name its columns.
$searchThere is no free-text search across fields. Use the text filter on a column, or a search engine index with the contains filter.
any and all (lambda operators)They need a collection property, which a flat source does not have. Denormalize, or filter in a view.
Arithmetic (add, sub, mul, div, mod) and $computeThe operator set is closed so every operator has a tested meaning on every database (AR-6 of the technical requirements). Expose the computed value as a column of the source.
Functions in $filter and $orderby (tolower, toupper, trim, concat, substring, length, indexof, year, month, day, round, now)The same reason. Case-insensitivity is already the default for text, and a date part is a column or a range on the date.
$apply=filter(...) before groupbyPut it in filterModel or customFilters: it filters the rows before they are grouped, as OData does.
$apply with a filter after aggregate (the SQL HAVING), topcount, concat, join, compute, rollupOne grouping request has one level and the five aggregates, and filterModel always filters rows before they are aggregated. Filter the groups after the query.
countdistinct, $count inside aggregate, custom aggregatesThe aggregate set is closed: sum, min, max, avg, count.
$batch, $format, $metadata, $value, actions and functionsThey are about the transport and the service, not the query. Craticula compiles a query and has no service layer.

Next #