Home Reference Source
import Schema from 'Neo4Jay/lib/schema.js'
public class | source

Schema

define the structure of your data, schema specific methods, indexes / constrains, hooks, validation, relationships,

Constructor Summary

Public Constructor
public

constructor(object: *, options: *)

Used to initialize a new schema.

Member Summary

Public Members
public

methods: *

public

Method Summary

Public Methods
public

Adds an instance relationship to documents constructed from Models compiled from this schema.

public

Function to use for validating a node

Public Constructors

public constructor(object: *, options: *) source

Used to initialize a new schema.

Params:

NameTypeAttributeDescription
object *
options *

Example:

import Neo4Jay from 'neo4jay';

const Schema = Neo4Jay.Schema;

const ingredientSchema = new Schema({
	name: {
		required: true,
		type: String
	},
	description: {
		type: String
	}
})

Public Members

public methods: * source

public relationships: * source

Public Methods

public relationsship(rel: function) source

Adds an instance relationship to documents constructed from Models compiled from this schema.

Params:

NameTypeAttributeDescription
rel function

The relation type and options for the specific relationship, can only accept one relationship at the time.

Example:


const Schema = Neo4Jay.Schema;
const Model = Neo4Jay.model;
const Relations = Neo4Jay.Relations;
ingredientSchema.relationsship(
		Relations.hasMany('Nutrient', {
  		name: 'HAS_NUTRIENT',
   		schema: new Schema({
   			amount: {
     			type: Number,
       			required: true
         	}
         })
     })
)

const Schema = Neo4Jay.Schema;
const Model = Neo4Jay.model;
const Relations = Neo4Jay.Relations;

ingredientSchema.relationsship(
		Relations.belongsToOne('IngredientType', {
 		name: 'HAS_INGREDIENT'
   	})
)

public validate(node: object): object source

Function to use for validating a node

Params:

NameTypeAttributeDescription
node object

The node that will be evaluated

Return:

object

node - The evaluated node with added or removed properties.

Throw:

ValidationError

error - Thrown if an node violates the constraints given by the schema.