beg*_*er_ 7 sql jquery query-builder
我找到了http://redquerybuilder.appspot.com/,但这会生成我希望避免的SQL客户端.在帽子页面上有一个指向JQuery Query Builder插件的链接,但该链接转到jquery主页.看起来这个插件不再存在了(另请参阅JQuery中的简单SQL查询生成器以获得相同的链接).
我找到了http://kindohm.com/posts/2013/09/25/knockout-query-builder/,它看起来非常符合我的要求,除了我不想添加另一个JavaScript库.
最后有http://devtools.korzh.com/easyquery/javascript/docs/javascript-query-builder-php,看起来非常好.但他们使用Web服务生成SQL,您必须获得一个API密钥才能生效.现在它是免费的...但看起来像一个很好的陷阱诱使用户,然后当他们不能轻易逃脱时,可能会开始收取Web服务或可以随时关闭它.
因此,在我构建自定义查询表单之前,是否存在这样的查询构建器?
Mis*_*tic 25
我需要一个查询构建器,它可以生成一个很好的JSON,我可以用来创建Java POJO并写下这个:http:
//mistic100.github.io/jQuery-QueryBuilder
编写一个创建SQL查询的解析器会很容易.
Chr*_*ris 10
我推荐Mistic的作品.其他Pro的选择:
$operators = array('equal' => "=",
'not_equal' => "!=",
'in' => "IN (?)",
'not_in' => "NOT IN (_REP_)",
'less' => "<",
'less_or_equal' => "<=",
'greater' => ">",
'greater_or_equal' => ">=",
'begins_with' => "ILIKE",
'not_begins_with' => "NOT ILIKE",
'contains' => "ILIKE",
'not_contains' => "NOT ILIKE",
'ends_with' => "ILIKE",
'not_ends_with' => "NOT ILIKE",
'is_empty' => "=''",
'is_not_empty' => "!=''",
'is_null' => "IS NULL",
'is_not_null' => "IS NOT NULL");
$jsonResult = array("data" => array());
$getAllResults = false;
$conditions = null;
$result = "";
$params = array();
$conditions = json_decode(utf8_encode($_POST['c']), true);
if(!array_key_exists('condition', $conditions)) {
$getAllResults = true;
} else {
$global_bool_operator = $conditions['condition'];
// i contatori servono per evitare di ripetere l'operatore booleano
// alla fine del ciclo se non ci sono più condizioni
$counter = 0;
$total = count($conditions['rules']);
foreach($conditions['rules'] as $index => $rule) {
if(array_key_exists('condition', $rule)) {
$result .= parseGroup($rule, $params);
$total--;
if($counter < $total)
$result .= " $global_bool_operator ";
} else {
$result .= parseRule($rule, $params);
$total--;
if($counter < $total)
$result .= " $global_bool_operator ";
}
}
}
/**
* Parse a group of conditions */
function parseGroup($rule, &$param) {
$parseResult = "(";
$bool_operator = $rule['condition'];
// counters to avoid boolean operator at the end of the cycle
// if there are no more conditions
$counter = 0;
$total = count($rule['rules']);
foreach($rule['rules'] as $i => $r) {
if(array_key_exists('condition', $r)) {
$parseResult .= "\n".parseGroup($r, $param);
} else {
$parseResult .= parseRule($r, $param);
$total--;
if($counter < $total)
$parseResult .= " ".$bool_operator." ";
}
}
return $parseResult.")";
}
/**
* Parsing of a single condition */
function parseRule($rule, &$param) {
global $fields, $operators;
$parseResult = "";
$parseResult .= $fields[$rule['id']]." ";
if(isLikeOp($rule['operator'])) {
$parseResult .= setLike($rule['operator'], $rule['value'], $param);
} else {
$param[] = array($rule['type'][0] => $rule['value']);
$parseResult .= $operators[$rule['operator']]." ?";
}
return $parseResult;
}
Run Code Online (Sandbox Code Playgroud)