Neode - Object Graph Mapper for Node JS

kudos-5

(Adam Cowley) #1

Neode is a Neo4j OGM for Node JS designed to take care of the CRUD boilerplate involved with setting up a neo4j project. The idea is to reduce the amount of code it takes to start a Neo4j project in with node. Just set up your models, create a Neode instance in your project and off you go...

I wrote an article on Medium explaining my inspiration and how to get started.

If you have any problems or have feedback, feel free to reply here or open up an issue. Pull Requests are also more than welcome.

Main Repository: https://github.com/adam-cowley/neode
Example Project: https://github.com/adam-cowley/neode-example

Happy coding!


(Benfluleck) #2

Hi @adam.cowley I was wondering if you have any examples of your OGM creating relationships between 2 nodes. I have been trying to see if I can use your OGM to achieve this without having to write a cypher.

Thanks


(Adam Cowley) #3

Hi Ben,

At the moment you would need to do something like the following. It's not ideal but this assumes that you need to load the two nodes.

const person1 = neode.find('Person', id1);
const person2 = neode.find('Person', id2);

person1.relateTo(person2, rel_type, properties)
  .then(rel => console.log(rel.id)

Or if you don't have the nodes loaded, you could pass through the information into a merge call:

neode.merge('Person', {
  id: 1,
  knows: [ {id: 2} ]
})

Let me know if that helps.


(Benfluleck) #4

so using knows as the relationship or would we have to explicitly define this in the Model.

module.exports: {
...knows : {
}
}

I would definitely be interested in using both methods but at the moment I am just getting to grips to define the relationships. I will let you know how I get on thanks


(Adam Cowley) #5

Knows would need to be defined in both scenarios. What are you trying to do? It would be easier to advise if I know what you're trying to do.


(Benfluleck) #6

Might as well thanks for the help :) . I am trying to construct a test project, it's a population management system. In the system, you define parent locations and any subsequent child locations defined are nested in their parents. And so on.

I defined the model as

module.exports = {
labels: ["Location"],

name: {
type: 'string',
unique: 'true', // Creates a Unique Constraint
},

id: {
primary: true,
type: 'uuid',
required: true, // Creates an Exists Constraint in Enterprise mode
},
malePopulation: {
type: 'number',
},
femalePopulation: {
type: 'number',
},
totalPopulation: {
type: 'number',
},
located_in: {
type: "relationship",
target: "Location",
relationship: "LOCATED",
direction: "in",
properties: {
name: "string"
},
}
}

I am using a Neo4j DB on GrapheneDB. At the moment I have only been able to create the nodes but no relationships. The final aim is to be able to update a child location and for those changes to reflect in the parents e.g. If I had a parent Location called U.S.A with a child New York which also had a child Maine. Updates in Maine and New York would reflect in U.S.A. Thanks for the help


(Benfluleck) #7

Aren't person1 and person2 Promises? Shouldn't it be:

location1.then(
  (res) => {
    res.relateTo(location2, 'located_in')
      .then(rel => console.log(rel.id))

  }
)

(Knightkronos9510) #8

Hi @adam.cowley I having issues with neode, please see what I get when I try to create a node

As you can see when I run the create command using a neode instance the promise didn't resolve sucessfuly, I review also the model and connection settings are right, so I don't know what's wrong, Would you help me?


(The Graph Giraffe) #9

Thanks for submitting!

I’ve added a tag that allows your blog to be displayed on the community home page!


(Adam Cowley) #10

I don't think the function in the router is asynchronous, I'm not sure whether removing async will solve the problem or not.

You can also use res.toJson() to return a cleaner JSON object with its properties rather than using JSON.stringify.

What version of neode are you using? Do you have a repository that I can clone and take a look at?


(Simon) #11

Hi, I'm having some trouble understanding what I have to do. I have used:

.with({
    User: require('./models/User'),
    Skill: require('./models/Skill')
  })

And
.schema.install().then(() => console.log('schemas installed')))

But my models don't appear in the db until I create a node of that type?

What does .schema.install() actually do? And do I have to do any .model() commands?

Regards