cypher-talker
Advanced tools
Comparing version 0.5.1 to 0.6.0
{ | ||
"name": "cypher-talker", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Simple ES6/7-oriented lib to work with neo4j and (in future) with OpenCypher-compatible databases", | ||
"main": "build/index.js", | ||
"main": "index.js", | ||
"module": "index.mjs", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-register --require ./test/globals/lib", | ||
"test-against-build": "mocha --bail --reporter nyan --require ./test/globals/build", | ||
"build": "babel lib --out-dir build", | ||
"preversion": "git add lib/* test/* && npm run build && npm run test-against-build", | ||
"postversion": "jscs --fix lib && git commit --amend --no-edit && git push -u origin master && npm publish && rm -rf ./build" | ||
"test": "ava", | ||
"test:dev": "ava --watch", | ||
"build": "rollup index.mjs --format commonjs --file index.js" | ||
}, | ||
@@ -21,16 +20,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel-cli": "^6.3.17", | ||
"babel-polyfill": "^6.3.14", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-preset-stage-1": "^6.3.13", | ||
"babel-register": "^6.3.13", | ||
"chai": "^3.4.1", | ||
"chai-as-promised": "^5.1.0", | ||
"jscs": "^2.7.0", | ||
"mocha": "^2.3.4" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"neo4j": "^2.0.0-RC2" | ||
"ava": "^3.11.1", | ||
"rollup": "^2.26.2" | ||
} | ||
} |
@@ -1,49 +0,76 @@ | ||
# Simple ES6/7-oriented lib to work with neo4j and (in future) with OpenCypher-compatible databases | ||
_this software is early alpha stage and is not supposed to be used in production_ | ||
# Cypher-talker: Tag strings for neo4j | ||
_Intended to be used as backing layer for other libraries_ | ||
Tired of writing neo4j queries like this? | ||
```javascript | ||
s.run('MERGE (alice:Person {name : $nameParam, age : $ageParam})', { | ||
nameParam: 'Alice', | ||
ageParam: 21 | ||
}) | ||
``` | ||
## Usage example | ||
Try `cypher-talker` to write like this: | ||
```javascript | ||
import t from 'cypher-talker' | ||
s.run(...t`MERGE (alice:Person {name : ${'Alice'}, age : ${21})`) | ||
``` | ||
Or even like this: | ||
```javascript | ||
console.log(Cypher.tag`test: ${'testVar'}`.getRawQuery()) | ||
// => {query: 'test: {v0}', params: {v0: 'testVar'}} | ||
import t from 'cypher-talker' | ||
const alice = {name: 'Alice', age: 21} | ||
s.run(...t`MERGE (alice:Person ${t(alice)})`) | ||
``` | ||
and embedded requests: | ||
It converts template strings to real queries with params, primitives and objects to query variables, | ||
allows nested queries and even has special (yet simple) syntax for inlining and object spread. | ||
It just works. | ||
### Installation | ||
Just run `npm i cypher-talker` or `pnpm i cypher-talker` or `yarn add cypher-talker`, whatever you like. | ||
Then use it. It ships with single default export. | ||
```javascript | ||
const req = Cypher.tag`test2: ${`testVar`}` | ||
console.log(Cypher.tag`test${req}`.getRawQuery()) | ||
// => {query: 'test: test2: {v0_0}', params: {v0_0: 'testVar'}} | ||
import t from 'cypher-talker' | ||
// or | ||
const t = require('cypher-talker') | ||
``` | ||
Utility helpers: | ||
It ships both with CommonJS and ESM packages, runs in latest browsers and NodeJS. | ||
It even should work with Deno. It is single-module package (use `index.mjs`) | ||
## Variables | ||
Just use variables. Cypher-talker will extract them. | ||
Variables come in incremental order, `v0`, then `v1`, `v2` and so on. | ||
```javascript | ||
//Cypher.raw: | ||
Cypher.tag`CREATE (entry:${Cypher.raw(label)})` | ||
//cypher.literal - iterates over object so it can be used for props: | ||
Cypher.tag`MATCH (target ${Cypher.literal(props)})` | ||
const q = t`hello ${'world'}` | ||
console.log([...q]) // ['hello {v0}', {v0: 'world'}] | ||
``` | ||
## API | ||
```typescript | ||
export class Connection { | ||
constructor(/*neo4j arguments for now*/) | ||
} | ||
## Nested queries | ||
export class Cypher { | ||
static defaultPrefix: string = 'v' | ||
static raw(string): Cypher.Raw | ||
static tag(Array<string>, ...Array<any>): Cypher // used as string tag | ||
static literal(Object): Cypher | ||
getRawQuery(): {query: string, params: Object} | ||
} | ||
If you need to re-use query parts, just inline them. No nesting limits. | ||
```javascript | ||
const q1 = t`hello` | ||
const q2 = t`${q1} world` | ||
console.log([...q2]) // ['hello world', {}] | ||
``` | ||
## Roadmap | ||
- [ ] request optimisation | ||
## Spreading the object | ||
Sometimes you want to pass object where you cannot really pass variable - like into the pattern-matching query. | ||
Use `t()` instead. | ||
```javascript | ||
const q = t`${t({hello: 'world'})}` | ||
console.log([...q]) // ['hello: {v0}', {v0: 'world'}] | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
3
77
6046
6
72
1
- Removeddebug@^2.2.0
- Removedneo4j@^2.0.0-RC2
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.0(transitive)
- Removedneo4j@2.0.0-alpha5(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removedunderscore@1.7.0(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)