Skip to content

Checking if a value exists in a Record #82

Closed
@legraphista

Description

@legraphista

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions