Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypher-talker

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypher-talker - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

.github/workflows/npm-publish.yml

27

package.json
{
"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'}]
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc