forked from codex-digital/cypher-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (40 loc) · 1.3 KB
/
index.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
45
46
47
48
49
var CypherStream = require('./CypherStream');
var toNative = require('./util/to-native')
var neo4j = require('neo4j-driver').v1;
var R = require('ramda');
var TransactionStream = require('./TransactionStream');
var all = R.all;
var compose = R.compose;
var cond = R.cond;
var isNil = R.isNil;
var not = R.not;
var unapply = R.unapply;
var always = R.always;
var notNil = compose(not, isNil);
/**
* user -> pass -> auth | undefined
*/
var auth = cond([
[unapply(all(notNil)), neo4j.auth.basic ],
[R.T, always(undefined)],
]);
module.exports = function Connection(url, username, password) {
var driver = neo4j.driver(url || 'bolt://localhost', auth(username, password));
var factory = function CypherStreamFactory(statement, parameters, options) {
if (parameters) {
statement = [ { statement, parameters } ];
}
var session = driver.session();
return new CypherStream(session, statement, options)
.on('end', () => session.close());
};
factory.transaction = options => {
var session = driver.session();
return new TransactionStream(session, options)
.on('end', () => session.close());
};
factory.driver = driver;
factory.neo4j = neo4j;
factory.toNative = toNative;
return factory;
};