Back to Top

neo4j-schema 0.2.4

A dead-simple client for neo4j in Javascript.

constructor(options)

Database constructor.

Parameters

Name Type Description
options Object

DB options.

options.conn Object

Connection options (uri: <String>, username: <String>, password: <String>).

options.maxSessionCount Integer

Maximum in-parallel sessions running inside the DB instance.

options.maxWaitingCount Integer

Maximum requests waiting in queue to acquire session.

Examples

const db = new Neo4JDB({conn: {uri: 'bolt://localhost:7474', username: 'neo4j', password: 'neo4j'}}).connect();

Returns

DB

connect(configs)

Connect to database.

Parameters

Name Type Description
configs Object

Returns

DB

model(name, schema)

Defines a model in database.

Parameters

Name Type Description
name String

Name of model as marked in DB.

schema Schema

The data schema such model should be compliant with.

Examples

const Neo4j = require('neo4j-schema');
let person = Neo4j.model(
     'person',
     Neo4j.Schema({
         name: String,
         age: Number,
         group: [String]
     })
);

Returns

Model

constructor(callee, model, opts)

The Query constructor used for building queries. This could be instantiated by calling Model behavioural functions such as Model.match().

Parameters

Name Type Description
callee DB Session

The callee to run such query when it's been constructed.

model Function.<Model>

The model of which such query should be constrained to.

opts Object

Returns

Void

match(patterns)

Match clause.

Parameters

Name Type Description
patterns Array.<Pattern> Array.<String>

Examples

match('patternStr' | {label: 'str', variable: 'n'});

Returns

Query

hasRelation(pattern)

Basic relation clause, also known as --.

Parameters

Name Type Description
pattern Object.<Pattern> String

Returns

Query

hasDirectedRelation(pattern)

Directed relation clause, also known as -->.

Parameters

Name Type Description
pattern Object.<Pattern> String

Returns

Query

hasReverseDirectedRelation(pattern)

Reverse directed relation clause, also known as <--.

Parameters

Name Type Description
pattern Object.<Pattern> String

Returns

Query

toNode(pattern)

The node such query should point to.

Parameters

Name Type Description
pattern Object.<Pattern> String

Returns

Query

where(filters, options)

Where clause.

Parameters

Name Type Description
filters Object.<Filters>

A filters map object that bears exactly the same APIs as in MongoDB.

options

Examples

.where({
     user: {
          name: {
             $in: ['Tom', 'Jack', 'House']
          },
          age: {
             $gte: 20,
             $lte: 40
          }
    }
})

Returns

Query

orderBy(params)

Order By clause.

Parameters

Name Type Description
params Object

Sort the matched documents by properties.

Examples

.orderBy({
     name: 1     // sort by field "name" in alphanumeric order
     age: -1     // and then sort by field "age" in descendant order.
})

Returns

Query

skip(num)

Skip clause.

Parameters

Name Type Description
num Number

Returns

Query

limit(num)

Limit clause.

Parameters

Name Type Description
num Number

Returns

Query

delete(vars, opts)

Delete clause.

Parameters

Name Type Description
vars Array.<String>

Variable names of nodes/relationships to delete from database.

opts Object
opts.isDetach Boolean

Decide if the matched instances should also remove all existing relationships during their deletion.

Returns

Query

detachDelete(vars)

Detach Delete clause. This method is equivalent to delete(vars, {isDetach: true}).

Parameters

Name Type Description
vars Array.<String>

Variable names of nodes/relationships to delete from database.

Returns

Query

remove(pattern)

Remove clause.

Parameters

Name Type Description
pattern Object.<Pattern> String

Returns

Query

removeProperty(variable, property)

Remove property of matched instance.

Parameters

Name Type Description
variable String

Variable name.

property String

Property name.

Returns

Query

with(fields)

With clause.

Parameters

Name Type Description
fields Array.<String>

The fields to carry over explicitly in a query.

Returns

Query

return(fields)

Return clause.

Parameters

Name Type Description
fields Array.<String>

The fields to return in a query.

Returns

Query

count()

Count clause.

Returns

Query

union()

Union clause.

Returns

Query

create(pattern)

Create clause.

Parameters

Name Type Description
pattern Object.<Pattern> String

The pattern specifying which instance to create.

Returns

Query

createMany(patterns)

Bulk creation clause.

Parameters

Name Type Description
patterns Object.<Pattern> String

The patterns to create in a single query.

Returns

Query

merge(pattern)

Merge clause.

Parameters

Name Type Description
pattern Object.<Pattern> String

The pattern specifying which instance to merge (update or create).

Returns

Query

set(pattern, upSert)

Set clause.

Parameters

Name Type Description
pattern Object.<Pattern> String

The pattern specifying which instance to update.

upSert Boolean

Decide if the properties of node matched should be created if doesn't exist.

Returns

Query

construct()

Return a string of constructed query.

Returns

String

new Pattern()

The pattern used to match nodes in the graph.

Returns

Void

Pattern.constructor(args, alphabet)

Parameters

Name Type Description
args Object String
args.variable String

Variable name.

args.label String Array.<String>

Label(s) of node.

args.props Object

Node properties map.

alphabet Function.<String>

Generate alphabet series.

Returns

Void

transpile(obj)

Transpile lean object to Joi schema.

Parameters

Name Type Description
obj Object

Examples

{
     id: {type: String, required: true},
     group: {type: String, default: 'User', enum: ['Admin', 'User']},
     age: {type: Number},
     createdAt: {type: Date, default: Date.now}
}

Returns

JoiSchema

model(db)

Return a model function.

Parameters

Name Type Description
db DB

The DB instance such model should inherit from.

Returns

Model

The compiled model function.

compile(db, methods)

Return a model function.

Parameters

Name Type Description
db
methods

Returns

Model