Closed
Description
There is no "proper" way to check if a value exists or not in a Record without trying to access and catching for errors.
Take this oversimplified example:
const queries = [
'MATCH (a:Apple) RETURN COUNT(a) AS apples' ,
'MATCH (a:Apple), (o:Orange) RETURN COUNT(a) AS apples, COUNT(o) AS oranges'
];
const query = queries[Math.random() > .5 ? 1 : 0];
session.run(query).then((data) => {
console.log(data[0].get('apples'));
// will throw if first query is chosen
console.log(data[0].get('oranges'));
});
There should be a way of checking for fields before trying to use them:
session.run(query).then((data) => {
console.log(data[0].get('apples'));
// will throw if first query is chosen
if(data[0].has('oranges')) {
console.log(data[0].get('oranges'));
}
});
Metadata
Metadata
Assignees
Labels
No labels