You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/export.mdx
+72-14Lines changed: 72 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,12 +24,6 @@ function formatQuery(
24
24
- MongoDB
25
25
- Common Expression Language (CEL)
26
26
27
-
:::info
28
-
29
-
The inversion operator (setting `not: true` for a rule group) is currently unsupported for the MongoDB format, but rules can be created using the `"!="` operator.
30
-
31
-
:::
32
-
33
27
For the next few sections, assume the `query` variable has been defined as:
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).
169
+
170
+
:::
171
+
172
172
### Common Expression Language
173
173
174
174
For Common Expression Language (CEL) output, use the "cel" format.
@@ -185,7 +185,65 @@ Output:
185
185
186
186
## Configuration
187
187
188
-
An object can be passed as the second argument instead of a string in order to have more detailed control over the output.
188
+
An object can be passed as the second argument instead of a string to have more fine-grained control over the output.
189
+
190
+
### Parse numbers
191
+
192
+
Since HTML `<input>` controls store values as strings (even when `type="number"`), exporting a query to various formats may produce a string representation of a value when a true numeric value is required or more appropriate. Set the `parseNumbers` option to `true` and `formatQuery` will attempt to convert all values to numbers, falling back to the original value if `parseFloat(value)` returns `NaN` (not a number).
193
+
194
+
```ts
195
+
const query:RuleGroupType= {
196
+
combinator: 'and',
197
+
not: false,
198
+
rules: [
199
+
{
200
+
field: 'digits',
201
+
operator: '=',
202
+
value: '20',
203
+
},
204
+
{
205
+
field: 'age',
206
+
operator: 'between',
207
+
value: '26, 52',
208
+
},
209
+
{
210
+
field: 'lastName',
211
+
operator: '=',
212
+
value: 'Vai',
213
+
},
214
+
],
215
+
};
216
+
217
+
// Default configuration - all values are strings:
218
+
formatQuery(query, { format: 'sql' });
219
+
// Returns: "(digits = '20' and age between '26' and '52' and lastName = 'Vai')"
220
+
221
+
// `parseNumbers: true` - numeric strings converted to actual numbers:
// Returns: "(digits = 20 and age between 26 and 52 and lastName = 'Vai')"
224
+
```
225
+
226
+
:::info
227
+
228
+
To avoid information loss, this option is more strict about what qualifies as "numeric" than [the standard `parseFloat` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat). Put simply, `parseFloat` works with any string that _starts_ with a numeric sequence, ignoring the rest of the string beginning with the first non-numeric character. When `parseNumbers` is `true`, `formatQuery` will only convert a `value` to a `number` if it appears to be numeric _in its entirety_ (after trimming whitespace).
Copy file name to clipboardExpand all lines: docs/api/import.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Use the `parseSQL` function to convert SQL `SELECT` statements into a format sui
13
13
function parseSQL(sql:string, options?:ParseSQLOptions):RuleGroupTypeAny;
14
14
```
15
15
16
-
`parseSQL` takes a SQL `SELECT` statement (either the full statement or the `WHERE` clause by itself). Try it out in the [demo](https://react-querybuilder.github.io/react-querybuilder/) by clicking the "Load from SQL" button.
16
+
`parseSQL` takes a SQL `SELECT` statement (either the full statement or the `WHERE` clause by itself). Try it out in the [demo](https://react-querybuilder.js.org/react-querybuilder/) by clicking the "Load from SQL" button.
17
17
18
18
The optional second parameter to `parseSQL` is an options object that configures how the function handles named or anonymous bind variables within the SQL string.
Copy file name to clipboardExpand all lines: docs/api/misc.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ function defaultValidator(query: RuleGroupType): {
20
20
21
21
Pass `validator={defaultValidator}` to automatically validate groups (rules will be ignored). A group will be marked invalid if either 1) it has no child rules or groups (`query.rules.length === 0`), or 2) it has a missing/invalid `combinator` and more than one child rule or group (`rules.length >= 2`).
22
22
23
-
You can see an example of the default validator in action in the [demo](https://react-querybuilder.github.io/react-querybuilder/) if you check the ["Use validation" option](https://react-querybuilder.github.io/react-querybuilder/#validateQuery=true). Empty groups will have bold text on their "+Rule" button and a description of the situation where the rules normally appear.
23
+
You can see an example of the default validator in action in the [demo](https://react-querybuilder.js.org/react-querybuilder/) if you check the ["Use validation" option](https://react-querybuilder.js.org/react-querybuilder/#validateQuery=true). Empty groups will have bold text on their "+Rule" button and a description of the situation where the rules normally appear.
Copy file name to clipboardExpand all lines: docs/api/querybuilder.mdx
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -661,35 +661,35 @@ The `translations` prop is optional, and each top-level property in the `transla
661
661
662
662
### `showCombinatorsBetweenRules`
663
663
664
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#showCombinatorsBetweenRules=true)
664
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#showCombinatorsBetweenRules=true)
665
665
666
666
Pass `true` to show the combinators (and/or) between rules and rule groups instead of at the top of rule groups. This can make some queries easier to understand as it encourages a more natural style of reading.
667
667
668
668
### `showNotToggle`
669
669
670
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#showNotToggle=true)
670
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#showNotToggle=true)
671
671
672
672
Pass `true` to show the "Not" (aka inversion) toggle switch for each rule group.
673
673
674
674
### `showCloneButtons`
675
675
676
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#showCloneButtons=true)
676
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#showCloneButtons=true)
677
677
678
678
### `showLockButtons`
679
679
680
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#showLockButtons=true)
680
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#showLockButtons=true)
681
681
682
682
Pass `true` to show the "Lock rule" and "Lock group" buttons. When a rule is locked, all elements within the rule will be disabled (except for the lock button, so the user can unlock it). When a group is locked, all elements within the group header (except the lock button), as well as all child rule/group elements, will be disabled.
683
683
684
684
### `resetOnFieldChange`
685
685
686
-
`boolean` (default `true`) [_Click for demo with this feature disabled_](https://react-querybuilder.github.io/react-querybuilder/#resetOnFieldChange=false)
686
+
`boolean` (default `true`) [_Click for demo with this feature disabled_](https://react-querybuilder.js.org/react-querybuilder/#resetOnFieldChange=false)
687
687
688
688
Pass `false` to avoid resetting the operator and value when the field changes.
689
689
690
690
### `resetOnOperatorChange`
691
691
692
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#resetOnOperatorChange=true)
692
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#resetOnOperatorChange=true)
693
693
694
694
Pass `true` to reset the value when the operator changes.
695
695
@@ -701,25 +701,25 @@ Pass `false` to disable the `onQueryChange` call on mount of the component which
701
701
702
702
### `autoSelectField`
703
703
704
-
`boolean` (default `true`) [_Click for demo with this feature disabled_](https://react-querybuilder.github.io/react-querybuilder/#autoSelectField=false)
704
+
`boolean` (default `true`) [_Click for demo with this feature disabled_](https://react-querybuilder.js.org/react-querybuilder/#autoSelectField=false)
705
705
706
706
Pass `false` to add an empty option (`"------"`) to the `fields` array as the first element (which will be selected by default for new rules). When the empty field option is selected, the operator and value components will not display for that rule.
707
707
708
708
### `addRuleToNewGroups`
709
709
710
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#addRuleToNewGroups=true)
710
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#addRuleToNewGroups=true)
711
711
712
712
Pass `true` to automatically add a rule to new groups. If a `query` prop is not passed in, a rule will be added to the root group when the component is mounted. If a `query` prop is passed in with an empty `rules` array, no rule will be added automatically.
713
713
714
714
### `independentCombinators`
715
715
716
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#independentCombinators=true)
716
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#independentCombinators=true)
717
717
718
718
Pass `true` to insert an independent combinator selector between each rule/group in a rule group. The combinator selector at the group level will not be available. Visually, this is similar to the [`showCombinatorsBetweenRules`](#showcombinatorsbetweenrules) option, except that each combinator selector is independently controlled. You may find that users take to this configuration more easily, as it can allow them to express queries more like they would in natural language.
719
719
720
720
### `enableDragAndDrop`
721
721
722
-
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#enableDragAndDrop=true)
722
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#enableDragAndDrop=true)
723
723
724
724
Pass `true` to display a drag handle to the left of each group header and rule. Clicking and dragging the handle element allows visual reordering of rules and groups.
725
725
@@ -731,12 +731,18 @@ Pass `true` to display a drag handle to the left of each group header and rule.
731
731
732
732
### `disabled`
733
733
734
-
`boolean | number[][]` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#disabled=true)
734
+
`boolean | number[][]` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#disabled=true)
735
735
736
736
Pass `true` to disable all subcomponents and prevent changes to the query. Pass an array of paths to disable specific rules and/or groups, e.g. `disabled={[[0]]}` will disable the first rule and its subcomponents but nothing else.
737
737
738
+
### `debugMode`
739
+
740
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#debugMode=true)
741
+
742
+
Pass `true` to log debugging information to the console.
743
+
738
744
### `validator`
739
745
740
-
`QueryValidator`[_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#validateQuery=true)
746
+
`QueryValidator`[_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#validateQuery=true)
741
747
742
748
This is a callback function that is executed each time `QueryBuilder` renders. The return value should be a boolean (`true` for valid queries, `false` for invalid) or an object whose keys are the `id`s of each rule and group in the query tree. If such an object is returned, the values associated to each key should be a boolean (`true` for valid rules/groups, `false` for invalid) or an object with a `valid` boolean property and an optional `reasons` array. The full object will be passed to each rule and group component, and all sub-components of each rule/group will receive the value associated with the rule's or group's `id`. See the [Validation](./validation) documentation for more information.
Copy file name to clipboardExpand all lines: docs/api/validation.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,7 @@ If you provide a query- or field-level validator function then the wrapper `<div
110
110
111
111
:::tip See it in action
112
112
113
-
In the [demo](https://react-querybuilder.github.io/react-querybuilder/), check the "Use validation" option and create an empty group or a text input without a value. Empty groups will show a message where the rules usually appear (using the `:after` pseudo-selector), and text fields without values will have a [purple](https://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/) outline.
113
+
In the [demo](https://react-querybuilder.js.org/react-querybuilder/), check the "Use validation" option and create an empty group or a text input without a value. Empty groups will show a message where the rules usually appear (using the `:after` pseudo-selector), and text fields without values will have a [purple](https://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/) outline.
114
114
115
115
:::
116
116
@@ -120,4 +120,4 @@ See the [validation section on the Export page](./export#validation) for more in
120
120
121
121
## Default validator
122
122
123
-
You can pass the provided [`defaultValidator`](./misc#defaultvalidator) to the `validator` prop to check for invalid combinators, empty groups, or (if `independentCombinators` is true) out-of-sequence `rules` arrays. The [demo](https://react-querybuilder.github.io/react-querybuilder/) uses the default validator.
123
+
You can pass the provided [`defaultValidator`](./misc#defaultvalidator) to the `validator` prop to check for invalid combinators, empty groups, or (if `independentCombinators` is true) out-of-sequence `rules` arrays. The [demo](https://react-querybuilder.js.org/react-querybuilder/) uses the default validator.
Copy file name to clipboardExpand all lines: docs/api/valueeditor.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ This query builder has been specially configured in two ways:
16
16
17
17
:::tip
18
18
19
-
The [compatibility packages](../compat) also implement these options using appropriate components from the associated style library ([see the demo](https://react-querybuilder.github.io/react-querybuilder/)).
19
+
The [compatibility packages](../compat) also implement these options using appropriate components from the associated style library ([see the demo](https://react-querybuilder.js.org/react-querybuilder/)).
@@ -113,9 +113,48 @@ This documentation primarily demonstrates use of the ESM and CommonJS builds of
113
113
114
114
:::
115
115
116
+
## Exporting queries
117
+
118
+
To convert a query object into other formats like [SQL](https://en.wikipedia.org/wiki/SQL), [MongoDB](https://www.mongodb.com/), and [CEL](https://github.com/google/cel-spec), you can use the `formatQuery` function ([full documentation here](./api/export)). The example below demonstrates the conversion of a query to its equivalent SQL form. Modify the query by manipulating the form elements and the SQL will update accordingly.
SQL as result of <code>formatQuery(query, 'sql')</code>:
146
+
</h4>
147
+
<pre>{formatQuery(query, 'sql')}</pre>
148
+
</>
149
+
);
150
+
};
151
+
```
152
+
153
+
</SandpackRQB>
154
+
116
155
## Onward and upward!
117
156
118
-
To discover all the options of React Query Builder, check out the [API documentation](./api/querybuilder). To play around with various configurations, check out the ["kitchen sink" demo](https://react-querybuilder.github.io/react-querybuilder/).
157
+
To discover all the options of React Query Builder, check out the [API documentation](./api/querybuilder). To play around with various configurations, including other export formats and [importing from SQL](./api/import), check out the ["kitchen sink" demo](https://react-querybuilder.js.org/react-querybuilder/).
0 commit comments