Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tungv/cypher.js
nodejs c++ addon to parse cypher query to AST
https://github.com/tungv/cypher.js
Last synced: 2 months ago
JSON representation
nodejs c++ addon to parse cypher query to AST
- Host: GitHub
- URL: https://github.com/tungv/cypher.js
- Owner: tungv
- Created: 2019-06-18T08:49:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:49:06.000Z (almost 2 years ago)
- Last Synced: 2024-04-24T15:10:14.763Z (8 months ago)
- Language: C++
- Size: 1.6 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# cypher.js
Utilities to parse, transform and format cypher query. Inspired by [node-cypher-parser](https://github.com/Loupi/node-cypher-parser) with 3 main differences:
1. this package can handle long query (longer than 1024 characters)
2. this package doesn't rename `node.type` from `libcypher-parser`
3. this package will eventually include a `format` utility to print an AST back to a string.# APIs
## 1. `parse(query)`
Accepts a cypher query string and try to parse it to Abstract Syntax Tree using native [libcypher-parser](https://github.com/cleishm/libcypher-parser).
Example:
```js
const { parse } = require('cypher.js');const result = parse("MATCH (n) RETURN n");
> console.log(require('util').inspect(result, { depth: null }))
/*
{ nnodes: 10,
eof: false,
errors: [],
root:
{ type: 'statement',
body:
{ type: 'query',
clauses:
[ { type: 'match',
optional: false,
pattern:
{ type: 'pattern',
paths:
[ { type: 'pattern-path',
elements:
[ { type: 'node-pattern',
identifier: { type: 'identifier', name: 'n' },
labels: [] } ] } ] },
hints: [] },
{ type: 'return',
distinct: false,
includeExisting: false,
projections:
[ { type: 'projection',
expression: { type: 'identifier', name: 'n' } } ] } ],
options: [] },
options: [] } }
*/
```## 2. `format(root, transform)`
_**Stability: experimental**_
Accepts a AST root and and optional transform function and returns a reformatted string.
Example:
```js
const { parse, UNSTABLE__format } = require('cypher.js');const result = parse('MATCH (n) RETURN n');
const reformatted = UNSTABLE__format(result.root);
// reformatted = "MATCH (n)\nRTURN n;"
```