neode icon indicating copy to clipboard operation
neode copied to clipboard

Validating and hydrating Models with custom queries

Open bboure opened this issue 7 years ago • 0 comments

Hi,

I have been testing this package for my latest project. I realized that most of the time, if not always, I find more convenient and performant to use the query builder instead of using the Model helpers. The reason is that I think it is better to just do everything in just one cypher query rather than several ones.

Example: I have a Person node in my db; I want to add a relation to that Person with another person. Using the Models helper I would have to do something like:

  1. find() Person 1
  2. find() Person 2
  3. Call person1.relateTo(person2)

That is 3 different queries when I could just

MATCH (p1:Person {id: 1}), (p2:Person {id: 2})
CREATE (p1)-[:KNOWS]->(p2)
RETURN p1, p2

(I did not find a way to do something like this through the models)

The query builder allows me that but I am missing a few things:

  • Validation: I find very convenient that the Model validates but also "marshals" the data types between neo4j types and JS types.

  • Hydratation: Models come hydrated when the query builder just returns plain Records directly from the driver. Hydration gives me some convenient helpers like toJson()

I think there is probably some margin here to solve those issues. We could probably rely on the Labels to know how to hydrate and validate inputs/results in the query builder (whenever possible).

What do you think?

bboure avatar Oct 18 '18 22:10 bboure