formatQuery
formatQuery signature
export const formatQuery = (value: DenormalizedQuery,format: QueryFormat,options?:| IFormatSqlOptions| IFormatMongoOptions| IFormatAqlOptions| IFormatJsonataOptions| IFormatJsonLogicOptions| IFormatCelOptions| IFormatDjangoOptions| IFormatDynamoOptions| IFormatElasticsearchOptions| IFormatSpelOptions| IFormatPrismaOptions| IFormatODataOptions| IFormatRsqlOptions) => string;
Supported formats
export type QueryFormat =| 'SQL'| 'Mongo'| 'AQL'| 'JSONata'| 'JsonLogic'| 'CEL'| 'Elasticsearch'| 'SpEL'| 'Prisma'| 'OData'| 'RSQL'| 'Dynamo'| 'Django';
Options types
export interface IFormatQueryBaseOptions {rootlessCombinator?: 'AND' | 'OR';modifierlessGroupCombinator?: 'AND' | 'OR';fields?: IBuilderFieldProps[];}export interface IFormatSqlOptions extends IFormatQueryBaseOptions {wrapWhereClause?: boolean;}export interface IFormatAqlOptions extends IFormatQueryBaseOptions {wrapFilterClause?: boolean;variableName?: string;}export interface IFormatElasticsearchOptions extends IFormatQueryBaseOptions {wrapQueryClause?: boolean;}export interface IFormatPrismaOptions extends IFormatQueryBaseOptions {wrapWhereClause?: boolean;}export interface IFormatODataOptions extends IFormatQueryBaseOptions {wrapFilterClause?: boolean;}
Parameters
valueThe denormalized query tree to serialize.formatThe target format. This determines both the formatter used and the shape of accepted options.optionsOptional formatter configuration.
Shared options
fieldsSupplies field metadata to the formatter. This is often required when output depends on field type, option labels, or value semantics.rootlessCombinatorChooses how root-level items are combined when the query does not have a single explicit root group. This matters most whensingleRootGroupis disabled.modifierlessGroupCombinatorChooses how children of modifierless groups are combined when a group has structure but no embedded AND/OR modifier.
Behavior notes
fieldsTreat this as recommended for anything beyond trivial string-only formatting, especially for typed values and list-backed fields.rootlessCombinatorIf your tree has multiple top-level nodes, this decides whether the exported expression joins them withANDorOR.modifierlessGroupCombinatorUse this when your UI allows groups without modifiers and your target syntax still needs a combinator in serialized output.
Format-specific options
wrapWhereClauseSupported by SQL and Prisma format options. Prefixes the output withWHERE.wrapFilterClauseSupported by AQL and OData format options. Prefixes the output withFILTERor equivalent filter clause semantics.variableNameSupported by AQL format options. Sets the document variable prefix used in generated expressions.wrapQueryClauseSupported by Elasticsearch format options. Wraps the generated expression in the outer query clause shape.
Field comparisons
Formatting a field-reference rule
const sql = formatQuery(data, 'SQL', {fields,wrapWhereClause: true,});// WHERE ORDER_TOTAL >= ORDER_APPROVAL_LIMIT
- Native support
SQL,Mongo,AQL,JSONata,JsonLogic,CEL,SpEL,Prisma,OData,Dynamo, andDjangoserialize field comparisons when the operator has a direct right-hand-side field form. fieldsoption Treat field metadata as strongly recommended here because formatter behavior depends on field semantics and operator compatibility.- Explicit rejection
ElasticsearchandRSQLintentionally throw forvalueSource: 'field'rules instead of inventing backend-only syntax.
See also
For a live sandbox that exercises these formats, use Parsing and Formatting.