Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ before_script:
env:
- ORIENTDB_VERSION=1.7.10
- ORIENTDB_VERSION=2.0.2
- ORIENTDB_VERSION=2.1-SNAPSHOT
9 changes: 7 additions & 2 deletions lib/db/class/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -296,4 +301,4 @@ exports.cacheData = function (classes) {
}

return this;
};
};
4 changes: 2 additions & 2 deletions lib/db/class/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 18 additions & 1 deletion lib/db/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -1015,4 +1032,4 @@ function encodeReturnObject (obj) {
parts[i] = utils.encode(key) + ":" + obj[key];
}
return '{'+parts.join(',')+'}';
}
}
20 changes: 20 additions & 0 deletions test/db/statement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down