0.2.7 • Published 6 years ago

neo4j-schema v0.2.7

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Neo4j Schema

npm version

A dead-simple client for neo4j in Javascript.

Features

  1. Mongoose-like syntax, flat learning curve, bootstrap Javascript developers to access Neo4J in minutes.
  2. Resource pooling, automatically reuse connection resources to cut down network overhead.
  3. Support schema validation with built-in Joi-schema.
  4. Support ES6, ES7 syntax.

Documentation

Installation

npm install --save neo4j-schema

Example

const Neo4JDB = require('neo4j-schema');
const Query = Neo4JDB.Query;
const db = new Neo4JDB({
    uri: 'bolt://localhost',
    username: 'neo4j',
    password: 'neo4j'
}).connect();

const PersonSchema = Neo4JDB.Schema({
            name: String,
            age: Number,
            isAdmin: {type: Boolean, default: false},
            tags: [String],
            createdAt: {type: Date, default: Date.now}
        });
const Person = db.model('person', PersonSchema);

// Create
Person.create({
          variable: 'n',
          label: 'Person',
          props: {
              name: 'foo',
              age: 25,
              tags: ['group A', 'group B', 'group C']
          }
      }).return(['*'])
        .exec()
        .then(docs => {
            console.log(docs);   // [Node {
                                 //      labels: ['Person'],
                                 //      properties: {
                                 //         name: 'foo',
                                 //         age: 25,
                                 //         tags: ['group A', 'group B', 'group C'],
                                 //         isAdmin: false,
                                 //         createdAt: 1529831729
                                 //      }
                                 // }]
        }).catch(e => {
             console.error(e);
        });

// Match
let query = new Query(db);      // alternatively, use Person.match()
query.match({
          variable: 'n',
          label: 'Person'
        })
        .where({
            name: 'foo',
            age: {$gt: 20}
        })
        .return(['*'])
        .exec()
        .then(docs => {
            console.log(docs);  // [Node {
                                //      labels: ['Person'],
                                //      properties: {
                                //          name: 'foo',
                                //          age: 25,
                                //          tags: ['group A', 'group B', 'group C'],
                                //          isAdmin: false,
                                //          createdAt: 1529831729
                                //      }
                                // }]
        }).catch(e => {
            console.error(e);
        });

// Set
Person.match({
    variable: 'n',
    label: 'Admin'
}).set({
    variable: 'n',
    props: {
        name: 'bar',
        age: 30
    }
}).return(['*'])
    .exec()
    .then(docs => {
        console.log(docs);   // [Node {
                             //      labels: ['Person', 'Admin'],
                             //      properties: {
                             //         name: 'bar',
                             //         age: 30,
                             //         tags: ['group A', 'group B', 'group C'],
                             //         isAdmin: false,
                             //         createdAt: 1529831729
                             //      }
                             // }]
    });

// Remove Label
Person.match({variable: 'n', label: 'Admin'})
    .remove({variable: 'n', label: 'Admin'})
    .return(['*'])
    .exec()
    .then(docs => {
        console.log(docs);   // [Node {
                             //      labels: ['Person'],
                             //      properties: {
                             //         name: 'bar',
                             //         age: 30,
                             //         tags: ['group A', 'group B', 'group C'],
                             //         isAdmin: false,
                             //         createdAt: 1529831729
                             //      }
                             // }]
    });

// Delete
Person.match({
    variable: 'n',
    label: 'Person'
}).detachDelete(['n'])
    .exec()
    .then(docs => {
        console.log(docs);   // Node deleted
    });
0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.5

6 years ago