Skip to content

Instantly share code, notes, and snippets.

@victorpavlenko victorpavlenko/Query
Created Jul 15, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.