ormneo
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -14,3 +14,3 @@ 'use strict'; | ||
test('Test create node', (assert) => { | ||
ORMNeoNode.create({ name: 'name', tes: 3 }, 'test').then((node) => { | ||
ORMNeoNode.create({ name: 'name', tes: 3 , date: new Date()}, 'test').then((node) => { | ||
assert.notEqual(node, null); | ||
@@ -17,0 +17,0 @@ assert.notEqual(node.id, null); |
@@ -26,2 +26,6 @@ 'use strict'; | ||
assert.equal(query, ''); | ||
query = builder._conditionToQuery({'name' : {$regex: '.*[tes]'} }); | ||
assert.equal(query, 'n.name =~ \'.*[tes]\''); | ||
query = builder._conditionToQuery({'name' : {$regex: 3} }); | ||
assert.equal(query, ''); | ||
assert.end(); | ||
@@ -28,0 +32,0 @@ }); |
@@ -21,2 +21,3 @@ 'use strict'; | ||
let value = _.omitBy(node, _.isUndefined); | ||
ORMNeoObjectParse.parseProperties(value); | ||
return new Promise((resolve, reject) => { | ||
@@ -23,0 +24,0 @@ let objectString = ORMNeoObjectParse.objectString(value); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
let createString = keys.reduce((result, current) => { | ||
if (current !== 'id') { | ||
if (current !== 'id' && !_.isUndefined(node[current])) { | ||
return result + `${(result === '') ? '' : ','} ${current} : {${current}}`; | ||
@@ -21,4 +21,16 @@ } | ||
} | ||
static parseProperties(node) { | ||
if (node && _.isObject(node)) { | ||
_.forIn(node, (value, key) => { | ||
//Parsing date object | ||
if (_.isDate(value)) { | ||
node[key] = value.getTime(); | ||
} | ||
}); | ||
} | ||
return {}; | ||
} | ||
} | ||
module.exports = ORMNeoObjectParse; |
@@ -154,3 +154,4 @@ 'use strict'; | ||
$gte: '>=', | ||
$ne: '!=' | ||
$ne: '!=', | ||
$regex: '=~' | ||
}; | ||
@@ -162,3 +163,3 @@ let property = _.first(_.keysIn(filter)); | ||
let operator = conditionsMap[key]; | ||
if (operator) { | ||
if (operator && this._isFilterValid(operator, conditions[key]) ) { | ||
return ((result !== '') ? result + ' AND ' : '') + | ||
@@ -172,5 +173,15 @@ `n.${property} ${operator} ${this._valueOnQuery(conditions[key])}`; | ||
} | ||
_isFilterValid(operator, value) { | ||
if (operator === '=~') { | ||
return _.isString(value); | ||
} | ||
return true; | ||
} | ||
_valueOnQuery(value) { | ||
if (_.isString(value)) { | ||
return `'${value}'`; | ||
} if (_.isDate(value)) { | ||
return `${value.getTime()}`; | ||
} else { | ||
@@ -177,0 +188,0 @@ return `${value}`; |
@@ -26,2 +26,4 @@ 'use strict'; | ||
static relate(nodeId, otherNodeId, type, properties = {}, unique = false) { | ||
ORMNeoObjectParse.parseProperties(properties); | ||
let value = _.omitBy(properties, _.isUndefined); | ||
return new Promise((resolve, reject) => { | ||
@@ -33,7 +35,7 @@ if (_.isInteger(nodeId) && _.isInteger(otherNodeId)) { | ||
MATCH (n2) WHERE ID(n2)=${otherNodeId} | ||
CREATE ${uniqueQuery} (n1)-[r:${type} ${ORMNeoObjectParse.objectString(properties)}]->(n2) | ||
CREATE ${uniqueQuery} (n1)-[r:${type} ${ORMNeoObjectParse.objectString(value)}]->(n2) | ||
RETURN r`; | ||
let session = ORMNeo.session(); | ||
let readTxResultPromise = session.readTransaction((transaction) => { | ||
return transaction.run(cypher, properties); | ||
return transaction.run(cypher, value); | ||
}); | ||
@@ -65,2 +67,3 @@ readTxResultPromise.then((result) => { | ||
static update(relationId, newProperties) { | ||
ORMNeoObjectParse.parseProperties(newProperties); | ||
let value = _.omitBy(newProperties, _.isUndefined); | ||
@@ -67,0 +70,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "ormneo", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "ORM abstraction layer for neo4j", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
1169360
1581