mistic100 / mistic100/jQuery-QueryBuilder

Issue with sql-support plugin

Open
#1,019 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.7k
Forks
544
PR merge metrics
No merged PRs in 30d

Description

Hi I have the following function
export function buildSQLQueryBuilder(columns,sqlBuilderID,sqlGeneratorID,sqlPreviewID,initialSql = null) { console.log(columns); // Destroy any previous instance $(#${sqlBuilderID}).queryBuilder('destroy'); $(#${sqlPreviewID}`).text('Click generate button to see SQL query');

const filters = [
{
id: '*', label: 'All', type: 'string',
operators: ['equal','not_equal','in','not_in','contains','not_contains','less','less_or_equal','greater','greater_or_equal','between','not_between','is_null','is_not_null']
},
...columns.map(col => ({
id: col, label: col, type: 'string',
operators: ['equal','not_equal','in','not_in','contains','not_contains','less','less_or_equal','greater','greater_or_equal','between','not_between','is_null','is_not_null']
}))
];

// Initialize with sql-parser support
$(#${sqlBuilderID}).queryBuilder({
plugins: ['sql-support'],
filters,
allow_empty: true,
default_condition:'AND',
display_empty_group: true,
allow_groups: true,
lang: {
operators: { like: 'LIKE', not_like: 'NOT LIKE' },
conditions:{ AND: 'AND', OR: 'OR' }
}
});

// If they passed in a preset SQL, import it into the builder:
if (initialSql) {
try {
$(#${sqlBuilderID})
.queryBuilder('setRulesFromSQL', initialSql, {
parser: 'MySQL', // or 'PostgreSQL' depending on your dialect
skipValidation: true // you can tweak this
});
} catch (e) {
console.error('SQL import failed', e);
}
}

// Generate SQL button
$(#${sqlGeneratorID}).off('click').on('click', function () {
const result = $(#${sqlBuilderID}).queryBuilder('getSQL', false);
let output = '-- No valid SQL generated --';

if (result && result.sql) {
  let sqlBody = result.sql
    .trim()
    .replace(/^(AND|OR)\s+/i, '');

  // your LIKE-capitalization logic...
  sqlBody = sqlBody.replace(
    /(\w+)\s+(NOT\s+)?LIKE\s+'(?:%?)([^'%]+)(?:%?)'/gi,
    (match, col, notPart, val) => {
      const op = (notPart||'').trim()==='NOT' ? 'NOT LIKE' : 'LIKE';
      if (op === 'LIKE') {
        return `(${col} LIKE '%${val}%' OR ${col} LIKE '%${val.toUpperCase()}%')`;
      } else {
        return `(${col} NOT LIKE '%${val}%' AND ${col} NOT LIKE '%${val.toUpperCase()}%')`;
      }
    }
  );

  output = 'WHERE ' + sqlBody;
}
$(`#${sqlPreviewID}`).text(output);

});
}` I get the console c.esc is not a function this leads me to believe there is an issue with the parser library that I have in my repo https://github.com/mistic100/sql-parser

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided buildSQLQueryBuilder function and reproduce the c.esc error when using the sql-support plugin and setRulesFromSQL. Inspect the linked mistic100/sql-parser dependency and its parser integration, then confirm the error is resolved without breaking SQL import or generation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, jquery, sql
Domain
database, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.