API Docs for: 1.0.0
Show:

Constraints Class

Defined in: src\constraints.js:1

The constraints are used to check the data integrity in the Neo4J database.
There are:

  1. Count constraints
  2. Bool constraints
  3. Free javascript constraints

Methods

check_all_fragments

(
  • bool_constraints
  • count_constraints
  • free_constraints
)
Promise

Checks bool, count and free constraints If one fails, the promise is rejected and contains the rejected_constraint

A constraint is an object with different attributes example attributes: query, min, max, code but also: error, error_code

Parameters:

  • bool_constraints Array
  • count_constraints Array
  • free_constraints Array

Returns:

Promise:

constraint_has_changes

(
  • constraint
  • constraint_type
  • fragment_id
)
Promise

Compares a new constraint to a saved constraint in order to detect whether changes were made

Example query:

// session = a neo4j session\r\n// session.run(cypher_string) returns a promise (see the docs)\r\nnew Promise(function(resolve, reject){\r\n    var variables = {"fragment_id": fragment_id};\r\n    session.run("MATCH(f:Fragment)-[]-(t:Token {value: 'Token'}) WHERE ID(f) = {fragment_id} RETURN t.value as value;", variables)\r\n        .then(function(result){ \r\n            var value;\r\n            result.records.forEach(function(res){\r\n                value = res.get('value');\r\n                if (value === "Token2") {\r\n                    reject("There was a token called Token.");\r\n                }\r\n            });\r\n            resolve();\r\n    }).catch(function(err){\r\n        reject(err);\r\n    });\r\n});

Parameters:

  • constraint Object
  • constraint_type String

    either count_constraint, bool_constraint or free_constraint

  • fragment_id Number

Returns:

Promise:

run_bool_constraint

(
  • constraint
  • fragment_id
)
Promise

Compares the output of the constraint's cypher query to the boolean 'true'

Necessary attribute of the constraint: query

Example query:

MATCH(f:Fragment)-[]-(t:Token {value: 'Token'}) WHERE ID(f) = {fragment_id} RETURN COUNT(t) > 0;

Parameters:

  • constraint Object
  • fragment_id Number

Returns:

Promise:

run_bool_constraint

(
  • constraint
  • fragment_id
)
Promise

Runs javascript code that has to return a new Promise(...) If it resolves then the constraint is fulfilled

Necessary attribute of the constraint: query

Example query:

// session = a neo4j session\r\n// session.run(cypher_string) returns a promise (see the docs)\r\nnew Promise(function(resolve, reject){\r\n    var variables = {"fragment_id": fragment_id};\r\n    session.run("MATCH(f:Fragment)-[]-(t:Token {value: 'Token'}) WHERE ID(f) = {fragment_id} RETURN t.value as value;", variables)\r\n        .then(function(result){ \r\n            var value;\r\n            result.records.forEach(function(res){\r\n                value = res.get('value');\r\n                if (value === "Token2") {\r\n                    reject("There was a token called Token.");\r\n                }\r\n            });\r\n            resolve();\r\n    }).catch(function(err){\r\n        reject(err);\r\n    });\r\n});

Parameters:

  • constraint Object
  • fragment_id Number

Returns:

Promise:

run_count_constraint

(
  • constraint
  • fragment_id
)
Promise

Counts the number of results retrieved from the database and compares it to given boundaries

Necessary attributes of the constraint: query, min, max

Example query:

MATCH(f:Fragment)-[]-(t:Token) WHERE ID(f) = {fragment_id} RETURN t

Parameters:

  • constraint Object
  • fragment_id Number

Returns:

Promise: