Database-parser Native Add-on
Parses a where clause string in JS arrow function format and returns the parsed structure as a JS object.
** Example **
const parser = new (require('database-parser').WhereClauseParser)();
console.log(JSON.stringify(parser.parseSync('x => x.id === 1'), null, 2));
// Prints:
/* {
"entities": [
"x"
],
"where": {
"type": 54,
"l": {
"type": 20,
"obj": {
"type": 1,
"name": "x"
},
"prop": "id"
},
"r": 1
}
}*/
function where(clause, context) {
const parsed = parser.parseSync(String(clause));
// Create SQL with `parsed` and `context`...
}
function someFunction(name) {
return where((x, y) => x.name.toLowerCase() === name.toLowerCase() && x.id === y.id, {name});
}
someFunction('test_name');
$sql
namespace
PostgreSQL In your index.d.ts
declaration file, add the line /// <reference path="./node_modules/@vendredix/database-parser/index.d.ts" />