jamesfer / cypher-query-builder

An flexible and intuitive query builder for Neo4j and Cypher.
http://jamesfer.me/cypher-query-builder/index.html
MIT License
104 stars 22 forks source link

Patterns or raw conditions in where clauses #158

Open Layvier opened 3 years ago

Layvier commented 3 years ago

Hi, thanks a lot for this library, it really cleaned up the logic of my recommendation engine :)

One issue I encountered though is that it doesn't seem possible to use patterns in where clauses such as described here. I had to use qb.raw(), but it doesn't fit nicely in it as I have to determine wether .where was already called or not:

const hasWhereClause = !!filter && !!filter.resourceTypeIn;
 if (hasWhereClause) {
        q.where({
          r: {
           type: inArray(filter.resourceTypeIn),
          },
        });
    }
    q.raw(`${hasWhereClause ? ' AND ' : 'WHERE '}(u)-[:CONSUMED]->(r)`);

Am I missing something, is there a better way to do it already ?

Also if supporting patterns in where conditions is too complex, maybe just adding the ability to add raw conditions in .where() would bring more flexibility already: it would also allow things like toLower(r.name) CONTAINS toLower($query).

Let me know what you think !