converts the value of QueryBuilder to an SQL query
config | object | optional, a configuration object of the SQL query |
rules | object | optional, an object of rules for filtering |
object | an object with an SQL query string and an array of values |
// calling the method with default parameters
// ({placeholders:false}, $$("qb").getValue()[0])
var sql = $$("qb").toSQL();
The configuration object contains the placeholders attribute with the boolean value:
var sql = $$("qb").toSQL({placeholders:true});
It provides two variants of converting the rules object of the Query Builder value. For example, let's take the following object:
{
"glue": "and",
"rules": [
{
"key": "fname",
"value": "Alex",
"rule": "equal"
}
]
};
{
code: "fname = ?",
values: [ "Alex" ]
};
{
code: "fname = Alex",
values: [ "Alex" ]
};
The returned object has two properties:
As a second parameter the method can take an object of rules used for filtering. To refer to the rules object, you should get the first element of the value array returned by the getValue method. For example:
// converts Query Builder value into SQL query with placeholders instead of real values
var sql = $$("qb").toSQL({placeholders:true},$$("qb").getValue()[0]);