Created
July 15, 2016 17:33
-
-
Save victorpavlenko/6284c12d3e3100605e0c66a0668ea89c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
seraph, | |
boltDriver, | |
to | |
} from '../modules'; | |
export function getCreatedBy({uuid}) { | |
var cypher = 'MATCH (n {uuid: {uuid}})-[r:CREATED_BY]->(m)' | |
+ 'RETURN m'; | |
return new Promise((resolve, reject) => { | |
seraph.queryAsync(cypher, {uuid}).then((results) => { | |
resolve(results[0]); | |
}).catch(err => reject(err)); | |
}); | |
} | |
export function getUpdatedBy({uuid}) { | |
var cypher = 'MATCH (n {uuid: {uuid}})-[r:UPDATED_BY]->(m)' | |
+ 'RETURN m'; | |
return new Promise((resolve, reject) => { | |
seraph.queryAsync(cypher, {uuid}).then((results) => { | |
resolve(results[0]); | |
}).catch(err => reject(err)); | |
}); | |
} | |
export function getNodeProps({uuid}) { | |
var cypher = 'MATCH (n {uuid: {uuid}}) RETURN n'; | |
return new Promise((resolve, reject) => { | |
seraph.queryAsync(cypher, {uuid}).then((results) => { | |
resolve(results.length ? results.shift() : results); | |
}).catch(err => reject(err)); | |
}); | |
} | |
export function getSimpleProp({uuid}, key) { | |
var cypher = 'MATCH (n {uuid: {uuid}})-[r:SIMPLE_PROP]->(m:' + to.pascal(key) + ')' | |
+ 'RETURN m'; | |
return new Promise((resolve, reject) => { | |
seraph.queryAsync(cypher, {uuid}).then((results) => { | |
if (results.length && | |
results[0] && | |
results[0].value) { | |
resolve(results[0].value); | |
} else { | |
resolve(null); | |
} | |
}).catch(err => reject(err)); | |
}); | |
} | |
export function getNestedProp({uuid}, key) { | |
var cypher = 'MATCH (n {uuid: {uuid}})-[r:NESTED_PROP]->(m:' + to.pascal(key) + ')' | |
+ 'RETURN m'; | |
return new Promise((resolve, reject) => { | |
seraph.queryAsync(cypher, {uuid}).then((results) => { | |
if (results.length) { | |
resolve(results.shift()); | |
} else { | |
resolve(null); | |
} | |
}).catch(err => reject(err)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment