6.7.0-alpha.0 • Published 6 months ago

@react-awesome-query-builder/core v6.7.0-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@react-awesome-query-builder/core

npm

This package has core functionality to import/export/store query, provides utils and core config. Can be used on server-side, does not require React.

Installation

npm i @react-awesome-query-builder/core --save

Usage

import {
  CoreConfig, Utils,
  // types
  TreeStore, TreeState, TreeActions, InputAction, JsonTree
} from '@react-awesome-query-builder/core';

// config
const config = {
  ...CoreConfig,
  fields: {
    name: {
      label: 'Name',
      type: 'text',
    },
    age: {
      label: 'Age',
      type: 'number',
    }
  }
};

// load from JSON
const initialTree = Utils.loadTree({
  id: '00001',
  type: 'group',
  children1: [
    {
      id: '00002',
      type: 'rule',
      properties: {
        field: 'age',
        operator: 'greater_or_equal',
        value: [18],
        valueSrc: ['value']
      }
    }
  ]
});
// or import from jsonLogic
// const initialTree = Utils.loadFromJsonLogic({
//   'and': [
//     {
//       '<=': [
//         {var: 'age'},
//         18
//       ]
//     }
//   ]
// }, config);

// create store to manipulate tree on backend
const reducer = TreeStore(config);
let state: TreeState = reducer({tree: initialTree});

// add rule `name == 'denis'`
const rootPath = [ state.tree.get('id') as string ];
const action = TreeActions.tree.addRule(config, rootPath, {
  field: 'name',
  operator: 'equal',
  value: ['denis'],
  valueSrc: ['value'],
  valueType: ['text']
});
state = reducer(state, action);

// export
const tree = Utils.getTree(state.tree);
const { logic } = Utils.jsonLogicFormat(state.tree, config);
const sql = Utils.sqlFormat(state.tree, config);
const spel = Utils.sqlFormat(state.tree, config);
const mongo = Utils.mongodbFormat(state.tree, config);
const elastic = Utils.elasticSearchFormat(state.tree, config);
console.log({ tree, logic, sql, spel, mongo, elastic });
6.7.0-alpha.0

6 months ago

6.6.11

10 months ago

6.6.12

10 months ago

6.6.13

9 months ago

6.6.14

8 months ago

6.6.15

6 months ago

6.6.5

10 months ago

6.6.4

12 months ago

6.6.7

10 months ago

6.6.10

10 months ago

6.6.6

10 months ago

6.6.9

10 months ago

6.6.8

10 months ago

6.6.4-alpha.0

1 year ago

6.6.1

1 year ago

6.5.2

1 year ago

6.6.0

1 year ago

6.6.3

1 year ago

6.6.2

1 year ago

6.5.1

1 year ago

6.5.0

1 year ago

6.3.0

2 years ago

6.4.1

2 years ago

6.4.0

2 years ago

6.4.2

2 years ago

6.1.2

3 years ago

6.2.0

3 years ago

6.1.3

3 years ago

6.1.1

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

6.0.0-beta.5

3 years ago

6.0.0-beta.4

3 years ago

6.0.0-beta.3

3 years ago

6.0.0-beta.2

3 years ago

6.0.0-beta.1

3 years ago

6.0.0-beta.0

3 years ago