jql2sql
Version:
Transpiling JQL to SQL
40 lines (32 loc) • 935 B
JavaScript
const { parseJQL, transpile2SQL } = require('../../index.js')
{
const expr = 'a b c d e f g h = b';
it(expr, () => {
const ast = parseJQL(expr);
const UIField2Column = new Map();
UIField2Column.set('a b c d e f g h', 'a_b_c_d_e_f_g_h');
const where = transpile2SQL(ast, UIField2Column);
expect(where).toBe('a_b_c_d_e_f_g_h = b');
});
}
{
const expr = 'a a ~ b';
it(expr, () => {
const ast = parseJQL(expr);
const UIField2Column = new Map();
UIField2Column.set('a a', 'a_a');
const where = transpile2SQL(ast, UIField2Column);
expect(where).toBe('a_a LIKE \'b\'');
});
}
{
const expr = 'a a ~ "bb cc"';
it(expr, () => {
const ast = parseJQL(expr);
const UIField2Column = new Map();
UIField2Column.set('a a', 'a_a');
const where = transpile2SQL(ast, UIField2Column);
console.log(where);
expect(where).toBe(`(a_a LIKE 'bb' or a_a LIKE 'cc')`);
});
}