This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@vendredix/database-parser
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

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');

PostgreSQL $sql namespace

In your index.d.ts declaration file, add the line /// <reference path="./node_modules/@vendredix/database-parser/index.d.ts" />

Readme

Keywords

none

Package Sidebar

Install

npm i @vendredix/database-parser

Weekly Downloads

1

Version

0.3.3

License

MIT

Last publish

Collaborators

  • vendredixdev