diff --git a/docs/api/export.mdx b/docs/api/export.mdx index 16219b2f83..5becf1f820 100644 --- a/docs/api/export.mdx +++ b/docs/api/export.mdx @@ -23,6 +23,8 @@ function formatQuery( - Parameterized SQL (with anonymous or named parameters) - MongoDB - Common Expression Language (CEL) +- Spring Expression Language (SpEL) +- JsonLogic For the next few sections, assume the `query` variable has been defined as: @@ -165,7 +167,7 @@ Output: :::info -For now, the MongoDB export format has two major shortcomings. For one, it does not support the inversion operator (setting `not: true` for a rule group), however rules _can_ be created using the `"!="` operator. Also, if the query uses [independent combinators](./querybuilder#independentcombinators), it will not be processed and `formatQuery(query, 'mongodb')` will always return the [fallback expression](#fallback-expression). +The MongoDB export format does not support the inversion operator (setting `not: true` for a rule group), however rules _can_ be created using the `"!="` operator. ::: @@ -183,6 +185,34 @@ Output: `firstName = "Steve" && lastName = "Vai"`; ``` +### Spring Expression Language + +For Spring Expression Language (SpEL) output, use the "spel" format. + +```ts +formatQuery(query, 'spel'); +``` + +Output: + +```ts +`firstName == 'Steve' and lastName == 'Vai'`; +``` + +### JsonLogic + +The "jsonlogic" format produces an object that can be processed by the `jsonLogic.apply` function (see https://jsonlogic.com/). + +```ts +formatQuery(query, 'jsonlogic'); +``` + +Output: + +```json +{ "and": [{ "==": [{ "var": "firstName" }, "Steve"] }, { "==": [{ "var": "lastName" }, "Vai"] }] } +``` + ## Configuration An object can be passed as the second argument instead of a string to have more fine-grained control over the output. @@ -308,9 +338,17 @@ const p = formatQuery(query, { ### Fallback expression -The `fallbackExpression` is a string that will be part of the output when `formatQuery` can't quite figure out what to do for a particular rule or group. The intent is to maintain valid syntax while (hopefully) not detrimentally affecting the query criteria. - -By default, `fallbackExpression` is `"(1 = 1)"` for the "sql", "parameterized", and "parameterized_named" formats, `"1 == 1"` for the "cel" format, and `"{$and:[{$expr:true}]}"` for the "mongodb" format. +The `fallbackExpression` is a string that will be part of the output when `formatQuery` can't quite figure out what to do for a particular rule or group. The intent is to maintain valid syntax while (hopefully) not detrimentally affecting the query criteria. If not provided, the default fallback expression for the given format will be used (see table below). + +| Format | Default `fallbackExpression` | +| --------------------- | ---------------------------- | +| "sql" | `"(1 = 1)"` | +| "parameterized" | `"(1 = 1)"` | +| "parameterized_named" | `"(1 = 1)"` | +| "mongodb" | `"{$and:[{$expr:true}]}"` | +| "cel" | `"1 == 1"` | +| "spel" | `"1 == 1"` | +| "jsonlogic" | `false` | ### Value sources