0.3.3 • Published 7 years ago

@vendredix/database-parser v0.3.3

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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" />

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.6

8 years ago

0.2.5-alpha.0

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago