-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries.js
44 lines (33 loc) · 1.14 KB
/
queries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var u = require('util')
var fs = require('fs')
var path = require('path')
var yaml = require('js-yaml')
var template = require('./utils/template')
// load queries from file
var fn = path.join(__dirname, 'queries.yaml')
var f = fs.readFileSync(fn, {encoding: 'utf8'})
var qs = yaml.safeLoad(f, {filename: fn})
// make cypher queries out of structure manipulation request
exports.mkQuery = function (request) {
var structure = request.structure
var operation = request.operation
if (!qs[structure]) {
throw new Error(u.format('No such structure "%s"', structure))
}
if (!qs[structure][operation]) {
throw new Error(u.format('No such operation "%s" on "%s"', operation, structure))
}
if (!qs[structure][operation].cypher) {
throw new Error(u.format('No cypher query defined for operation "%s" on "%s"', operation, structure))
}
// lookup query string and...
var cypher_string = qs[structure][operation].cypher
// ...string replace all occurances of «type»
var s = template(cypher_string, {type: request.type})
// neo4batch ready dictionary
return {
parameters: request,
statement: s
}
}
exports.structures = qs