neode icon indicating copy to clipboard operation
neode copied to clipboard

Doubts about defining attributes

Open nlbydcg opened this issue 6 years ago • 5 comments

Very good NPM package I have a little problem. Is there a GET SET method similar to mongoose for defining attributes? Serialization and deserialization are required when dealing with JSON

nlbydcg avatar Jul 02 '19 07:07 nlbydcg

I have revised your file.

Enabling NPM packages to support GET and SET

I'm not sure if you will add this method.

I put the code on my GitHub first, because my colleague also needs to use this NPM package, so I have to put it on gitHub.

If you mind, I'll delete this NPM package on my gitHub

nlbydcg avatar Jul 02 '19 09:07 nlbydcg

What are you trying to do?

There is an update method on nodes and relationships to set properties.

const node = neode.find('User', 1);
node.update({ property: 'value' });

In terms of serialising to JSON, you can call toJson on a node or a collection of nodes which will turn the properties and any eager attributes into JSON. Something like this:

neode.all('Movie', params, order , limit, skip)
       .then(res => {
           /*
             *`all` returns a NodeCollection - this has a toJson method that
             * will convert all Nodes within the collection into a JSON object
            */
           return res.toJson();
       })
        .then(json => {
           res.send(json);
       })

https://github.com/adam-cowley/neode-example/blob/master/routes/api.js#L34

Feel free to keep your forked repo. Any PR's are welcome if there are any bugs or features you think are missing.

adam-cowley avatar Jul 03 '19 11:07 adam-cowley

image

I want to implement the GET and SET methods that I call when I read and save data. Just like Mongoose @

nlbydcg avatar Jul 03 '19 13:07 nlbydcg

When I update, I define the type type type of the attribute as integer, but it doesn't work. node.update()

nlbydcg avatar Jul 05 '19 11:07 nlbydcg

I like this idea. I will see if I can find some time to implement it. If you need it imminently, feel free to submit a PR.

adam-cowley avatar Jul 11 '19 13:07 adam-cowley