New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

decypher

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decypher - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

src/batch.js

11

index.js

@@ -8,14 +8,17 @@ /**

var loader = require('./src/loader.js'),
builder = require('./src/builder.js');
helpers = require('./src/helpers.js'),
Batch = require('./src/batch.js'),
Query = require('./src/query.js');
// Version
Object.defineProperty(loader, 'version', {
value: '0.2.0'
value: '0.3.0'
});
// Attaching the other classes to the loader
loader.batch = null;
loader.builder = builder;
loader.helpers = helpers;
loader.Batch = Batch;
loader.Query = Query;
// Exporting
module.exports = loader;
{
"name": "decypher",
"version": "0.2.0",
"version": "0.3.0",
"description": "A handful of cypher utilities for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,2 +11,3 @@ [![Build Status](https://travis-ci.org/Yomguithereal/decypher.svg)](https://travis-ci.org/Yomguithereal/decypher)

* A simple [query builder](#query-builder).
* Miscellaneous [helpers](#helpers).

@@ -110,6 +111,6 @@ ## Installation

```js
var cypher = require('decypher').builder;
var Query = require('decypher').Query;
// Creating a query
var query = cypher()
var cypher = new Query()
.match('MATCH (n:Node)')

@@ -120,11 +121,11 @@ .where('n.title = {title}', {title: 'The best title'})

// Compiling to string
query.compile();
cypher.compile();
// or
query.toString();
cypher.toString();
// MATCH (n:Node)
// WHERE n.title = {title}
// RETURN n;'
// RETURN n;
// Retrieving the query's parameters
query.params();
cypher.params();
>>> {

@@ -134,14 +135,147 @@ title: 'The best title'

// Retrieving the query's statements as an array
cypher.statements();
>>> [
'MATCH (n:Node)',
'WHERE n.title = {title}',
'RETURN n'
]
// Retrieving all of the above at once
var {query, params, statements} = cypher.build();
// Note that multi words statements like `ORDER BY`
// have to be written in camel-case:
query.orderBy('n.title');
cypher.orderBy('n.title');
// You can also set a bunch of params at once
query.params({whatever: 'is needed'});
cypher.params({whatever: 'is needed'});
// If you need to pass multiple query parts at once & separated by a comma
// just pass an array of strings instead of a single string.
cypher.create(['(a:Actor)', '(m:Movie)']);
>>> 'CREATE (a:Actor), (m:Movie)'
// Finally, you can add arbitrary parts to the query if required
query.add('anything you want');
query.add('with {param}', {param: 'heart'});
cypher.add('anything you want');
cypher.add('with {param}', {param: 'heart'});
```
## Helpers
*Escaping identifiers*
```js
var helpers = require('decypher').helpers;
helpers.escapeIdentifier('Complex `Identifier`');
>>> '`Complex ``Identifier```'
```
*Escaping literal maps*
```js
var helpers = require('decypher').helpers;
helpers.escapeLiteralMap({
hello: 'world',
'complex key': 3
});
>>> '{hello: "world", `complex key`: 3}'
// Indicating parameter keys
helpers.escapeLiteralMap({
name: 'name',
number: 2
}, ['name']);
>>> '{name: {name}, number: 2}'
```
*Building node patterns*
```js
var helpers = require('decypher').helpers;
// Possible options are:
// * `identifier`: a string
// * `label`: a string
// * `data`:
// - if string, will produce a single parameter
// - if object, will stringify it
// * `paramKeys`: will be passed to escapeLiteralMap when stringifying data
helpers.nodePattern();
>>> '()'
helpers.nodePattern({
identifier: 'n',
label: 'Node'
});
>>> '(n:Node)'
helpers.nodePattern({
label: 'Node',
data: {title: 'Hello'}
});
>>> '(n:Node {title: "Hello"})'
helpers.nodePattern({
identifier: 'n',
data: 'paramName'
});
>>> '(n {paramName})'
helpers.nodePattern({
label: 'Chapter',
data: {title: 'title'},
paramKeys: ['title']
});
>>> '(:Chapter {title: {title}})'
```
*Building relationship patterns*
```js
var helpers = require('decypher').helpers;
// Possible options are:
// * `direction`: "in" or "out"
// * `identifier`: a string
// * `predicate`: a string or an array of strings
// * `data`:
// - if string, will produce a single parameter
// - if object, will stringify it
// * `paramKeys`: will be passed to escapeLiteralMap when stringifying data
helpers.relationshipPattern();
>>> '--'
helpers.relationshipPattern({
direction: 'out',
identifier: 'r',
predicate: 'KNOWS'
});
>>> '-[r:KNOWS]->'
helpers.relationshipPattern({
direction: 'in',
predicate: ['PLAYS_IN', 'KNOWS']
});
>>> '<-[:PLAYS_IN|:KNOWS]-'
helpers.relationshipPattern({
direction: 'in',
identifier: 'r',
data: 'paramName'
});
>>> '<-[r {paramName}]-'
helpers.relationshipPattern({
predicate: 'KNOWS',
data: {since: 1975}
});
>>> '-[:KNOWS {since: 1975}]-'
```
## Contribution

@@ -148,0 +282,0 @@

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