diff --git a/.travis.yml b/.travis.yml index f3cf06e..7b188f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,3 @@ before_script: env: - ORIENTDB_VERSION=1.7.10 - ORIENTDB_VERSION=2.0.2 - - ORIENTDB_VERSION=2.1-SNAPSHOT diff --git a/lib/db/class/index.js b/lib/db/class/index.js index e42d89d..25d86db 100644 --- a/lib/db/class/index.js +++ b/lib/db/class/index.js @@ -204,9 +204,10 @@ exports.list = function (refresh) { * @param {String} name The name of the class to create. * @param {String} parentName The name of the parent to extend, if any. * @param {String|Integer} cluster The cluster name or id. + * @param {Boolean} isAbstract The flag for the abstract class * @promise {Object} The created class object */ -exports.create = function (name, parentName, cluster) { +exports.create = function (name, parentName, cluster, isAbstract) { var query = 'CREATE CLASS ' + name; if (parentName) { @@ -216,6 +217,10 @@ exports.create = function (name, parentName, cluster) { if (cluster) { query += ' CLUSTER ' + cluster; } + + if(isAbstract) { + query += ' ABSTRACT'; + } return this.query(query) .bind(this) @@ -296,4 +301,4 @@ exports.cacheData = function (classes) { } return this; -}; \ No newline at end of file +}; diff --git a/lib/db/class/property.js b/lib/db/class/property.js index 9db2bcf..b512d56 100644 --- a/lib/db/class/property.js +++ b/lib/db/class/property.js @@ -35,8 +35,8 @@ Property.prototype.configure = function (config) { this.readonly = config.readonly || false; this.notNull = config.notNull || false; this.collate = config.collate || 'default'; - this.min = config.min || null; - this.max = config.max || null; + this.min = typeof config.min !== 'undefined' ? config.min : null; + this.max = typeof config.max !== 'undefined' ? config.max : null; this.regexp = config.regexp || null; this.linkedClass = config.linkedClass || null; if (config.custom && config.custom.fields) { diff --git a/lib/db/statement.js b/lib/db/statement.js index 1e53a53..a76697e 100644 --- a/lib/db/statement.js +++ b/lib/db/statement.js @@ -31,6 +31,18 @@ Statement.prototype.select = clause('select', '*'); */ Statement.prototype.traverse = clause('traverse', '*'); +/** + * A 'strategy' clause for traverse query + * @param {String} args The strategy how traverse should go in deep, + * either 'DEPTH_FIRST'|'BREADTH_FIRST', the first one is default + * @return {Statement} The statement object + */ +Statement.prototype.strategy = function (s) { + if (typeof s === 'string' && s.toUpperCase() === 'DEPTH_FIRST' || s.toUpperCase() === 'BREADTH_FIRST') { + this._state.strategy = s.toUpperCase(); + } + return this; +}; /** * Insert expression. @@ -813,6 +825,11 @@ Statement.prototype.buildStatement = function () { if (state.limit) { statement.push('LIMIT ' + (+state.limit)); } + + if (state.strategy && state.traverse) { + statement.push('STRATEGY ' + state.strategy); + } + if (state.skip) { statement.push('SKIP ' + (+state.skip)); } @@ -1015,4 +1032,4 @@ function encodeReturnObject (obj) { parts[i] = utils.encode(key) + ":" + obj[key]; } return '{'+parts.join(',')+'}'; -} \ No newline at end of file +} diff --git a/test/db/statement-test.js b/test/db/statement-test.js index 3b4e09e..9c20088 100644 --- a/test/db/statement-test.js +++ b/test/db/statement-test.js @@ -178,6 +178,26 @@ COMMIT \n\ this.statement.traverse('in("Thing")', 'out("Thing")'); this.statement.buildStatement().should.equal('TRAVERSE in("Thing"), out("Thing")'); }); + + it('should traverse in depth first', function () { + this.statement.traverse().strategy('DEPTH_FIRST').from('Abc'); + this.statement.buildStatement().should.equal('TRAVERSE * FROM Abc STRATEGY DEPTH_FIRST'); + }); + + it('should traverse in breadth first', function () { + this.statement.traverse().strategy('BREADTH_FIRST').from('#23:4'); + this.statement.buildStatement().should.equal('TRAVERSE * FROM #23:4 STRATEGY BREADTH_FIRST'); + }); + + it('should traverse with no strategy spec', function () { + this.statement.traverse().strategy('XYZ'); + this.statement.buildStatement().should.equal('TRAVERSE *'); + }); + + it('should traverse in breadth first and with limit', function () { + this.statement.traverse().strategy('BREADTH_FIRST').limit(2).from('Xyz'); + this.statement.buildStatement().should.equal('TRAVERSE * FROM Xyz LIMIT 2 STRATEGY BREADTH_FIRST'); + }); }); describe('Statement::while()', function () {