plugins.SqlSupport

  1. Home
  2. Classes
  3. plugins.SqlSupport

new SqlSupport( [ options ] )

Description

Allows to export rules as a SQL WHERE statement as well as populating the builder from an SQL query.

Parameters
Name Type Attributes Description
options object <optional>
Name Type Attributes Default Description
boolean_as_integer boolean <optional>
true

true to convert boolean values to integer in the SQL output

Details

Methods


getRulesFromSQL( query, stmt ) → {object}

Description

Convert a SQL query to rules

Returns
Fires
Throws

MissingLibraryError, SQLParseError, UndefinedSQLOperatorError

Details

getSQL( [ stmt [, nl [, data ] ] ] ) → {module:plugins.SqlSupport.SqlQuery}

Description

Returns rules as a SQL query

Parameters
Name Type Attributes Default Description
stmt boolean | string <optional>

use prepared statements: false, 'question_mark', 'numbered', 'numbered(@)', 'named', 'named(@)'

nl boolean <optional>
false

output with new lines

data object <optional>

current rules by default

Returns
Fires
Throws

UndefinedSQLConditionError, UndefinedSQLOperatorError

Details

setRulesFromSQL()

Description

Sets the builder's rules from a SQL query

Details

Type Definitions


SqlQuery

Properties
Name Type Description
sql string
params object
Details

Events


changer:getSQLField

Description

Modifies the SQL field used by a rule

Parameters
Name Type Description
field string
rule Rule
Returns
Details

changer:getSQLFieldID

Description

Returns a filter identifier from the SQL field

Parameters
Name Type Description
field string
value *
Returns
Details

changer:groupToSQL

Description

Modifies the SQL generated for a group

Parameters
Name Type Description
expression string
group Group
Returns
Details

changer:parseSQLNode

Description

Custom parsing of an AST node generated by SQLParser, you can return a sub-part of the tree, or a well formed group or rule JSON

Parameters
Name Type Description
AST object

node

Returns
Details

changer:ruleToSQL

Description

Modifies the SQL generated for a rule

Parameters
Name Type Description
expression string
rule Rule
value *
valueWrapper function

function that takes the value and adds the operator

Returns
Details

changer:sqlGroupsDistinct

Description

Given an existing group and an AST node, determines if a sub-group must be created

Parameters
Name Type Description
create boolean

true by default if the group condition is different

group object
AST object
current int

group level

Returns
Details

changer:sqlToGroup

Description

Modifies the group generated from the SQL expression (this is called before the group is filled with rules)

Parameters
Name Type Description
group object
AST object
Returns
Details

changer:sqlToRule

Description

Modifies the rule generated from the SQL expression

Parameters
Name Type Description
rule object
AST object
Returns
Details