neodm
Neo4j Graph Data Model
Last updated 10 months ago by catalint .
GPL-3.0 · Repository · Bugs · Original npm · Tarball
$ cnpm install neodm 
SYNC missed versions from official npm registry.

Build Status Coverage Status Dependency Status

Neo4j Graph Data Model

Greenkeeper badge

Also works with new bolt driver

Changes

3.2.0 : allow setRelationship & set to be used with simple object and not just Model instance or id

breaking: v3 no longer relies on neo4j id's and sets own id property if not set in model declaration

Usage

Setup

const NeoDM = require('neodm');
NeoDM.db.setDB('http://localhost:7474');
NeoDM.db.setLogger(console.log);

Model Declaration

const Joi = require('joi');
const Model = NeoDM.Model;

Simple model declaration

class User extends Model {
    static [Model.schema]() {

        return {
            username: Joi.string()
        };
    }
}

const johnData = { username: 'john' };
const john = new User(johnData);
yield john.save();

hasOne relationship

class User extends Model {
    static [Model.schema]() {

        return {
            username: Joi.string()
        };
    }

}

class Article extends Model {
    static [Model.schema]() {

        return {
            title: Joi.string().default('test'),
            author: Model.hasOne(User)
        };
    }
}

const johnData = { username: 'john' };
const john = new User(johnData);
yield john.save();


const article = new Article({ title: 'hello world', author: john });
yield article.save();

find( {property:value, anotherProp:value} )


class User extends Model {
    static [Model.schema]() {

        return {
            username: Joi.string()
        };
    }

}

const johnData = { username: 'john smith' };
const john = new User(johnData);
yield john.save();

const johnFromDB = yield User.find({ username: johnData.username });

find( [ id1, id2 ] )

const john = new User({ username: 'john' });
yield john.save();

const smith = new User({ username: 'smith' });
yield smith.save();

const users = yield User.find([smith.id, john.id]);

Full Model Declaration

class Author extends Model{
    static [Model.schema](){
        return {
            name:Joi.string()
        }
    }

    afterInit(){

        //no return
    }

    afterInflate(inflatedRelationshipKeys){

        return Promise;
    }

    beforeValidate(){

        return Promise;
    }
}

better see the tests

-signed gpg 3

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 38
Dependencies (7)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |