UNPKG

nodebook-nbql

Version:

Filter query language for nodebook

21 lines (17 loc) 750 B
/* globals describe, it */ var nbql = require('../lib/nbql'), knex = require('knex')({}), toSQL; toSQL = exports.toSQL = function (input, resource) { var parsedFilter = nbql.parse(input); return nbql.knexify(knex(resource), parsedFilter).toQuery(); }; describe('NBQL', function () { it('should correctly get from NBQL -> SQL', function () { toSQL('id:1', 'posts').should.eql('select * from "posts" where "posts"."id" = 1'); }); it('should correctly escape bad sequences', function () { (function () {toSQL('id:\'1 and 1‘=\'1`\'', 'posts');}).should.throw(); toSQL('id:\'1 and 1‘=\\\'1`\'', 'posts').should.eql('select * from "posts" where "posts"."id" = \'1 and 1‘=\\\'1`\''); }); });