neodm

3.2.0 • Public • Published

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

Package Sidebar

Install

npm i neodm

Weekly Downloads

7

Version

3.2.0

License

GPL-3.0

Last publish

Collaborators

  • catalint