-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneo4jApi.js
45 lines (41 loc) · 1.22 KB
/
neo4jApi.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
var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "abcde"));
function makeQuery(entityType, entityParams) {
return `MATCH (:${entityType} ${entityParams})`
}
function searchEntity(entityType, entityParams) {
var session = driver.session();
var cypherQuery = makeQuery(entityType, entityParams);
return session
.run(
`${cypherQuery} RETURN count(*)`
)
.then(result => {
session.close();
// put cypher query and totalCount into key-value store
// key is searchResultDbId
// add searchResultDbId to result object
return result;
})
.catch(error => {
session.close();
throw error;
});
}
function getSearchResult(searchResultDbId, paginationParams) {
// get cypher query and totalCount from key-value store
var session = driver.session();
return session
.run(`${cypherQuery} ${paginationParams} return entity`)
.then(result => {
session.close();
// include totalCount in the response
return result.records;
})
.catch(error => {
session.close();
throw error;
});
}
module.exports.searchEntity = searchEntity;
module.exports.getSearchResult = getSearchResult;