Skip to content

Instantly share code, notes, and snippets.

@victorpavlenko
Created July 15, 2016 17:33
Show Gist options
  • Save victorpavlenko/6284c12d3e3100605e0c66a0668ea89c to your computer and use it in GitHub Desktop.
Save victorpavlenko/6284c12d3e3100605e0c66a0668ea89c to your computer and use it in GitHub Desktop.
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