3.2.0 • Published 7 years ago

neodm v3.2.0

Weekly downloads
41
License
GPL-3.0
Repository
github
Last release
7 years ago

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

3.2.0

7 years ago

3.1.5

7 years ago

3.0.5

7 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

1.4.7

8 years ago

1.4.6

8 years ago

1.3.6

8 years ago

1.3.5

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.23

8 years ago

1.2.22

8 years ago

1.2.21

8 years ago

1.2.20

8 years ago

1.2.18

8 years ago

1.2.17

8 years ago

1.2.16

8 years ago

1.2.15

8 years ago

1.2.14

8 years ago

1.2.13

8 years ago

1.2.12

8 years ago

1.2.10

8 years ago

1.2.9

8 years ago

1.2.8

8 years ago

1.2.7

8 years ago

1.2.6

8 years ago

1.2.5

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago