Navigation Menu

Skip to content

Commit

Permalink
Sync methods can be chained
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 15, 2012
1 parent 67292b2 commit b194840
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/database/domain.js
Expand Up @@ -270,6 +270,8 @@ Domain.prototype = {
key_type: nroonga.ShortText,
default_tokenizer: nroonga.TokenBigram
});

return this;
},

deleteSync: function() {
Expand All @@ -285,12 +287,15 @@ Domain.prototype = {
this.context.commandSync('table_remove', {
name: this.termsTableName
});

return this;
},

reindexSync: function() {
this.indexFields.forEach(function(field) {
field.reindexSync();
});
return this;
},

getSynonymSync: function(key) {
Expand Down Expand Up @@ -357,6 +362,8 @@ Domain.prototype = {
table: this.synonymsTableName,
values: JSON.stringify(values)
});

return this;
},

setupBlankSynonymsTable: function() {
Expand All @@ -377,6 +384,8 @@ Domain.prototype = {
type: nroonga.ShortText,
flags: nroonga.COLUMN_VECTOR
});

return this;
},

hasSynonymsTableSync: function() {
Expand Down Expand Up @@ -425,6 +434,7 @@ Domain.prototype = {
table: this.tableName,
values: JSON.stringify(values)
});
return this;
},

toGrnDumpRecord: function(record) {
Expand All @@ -449,6 +459,7 @@ Domain.prototype = {
table: this.tableName,
key: id
});
return this;
},

setConfiguration: function(key, value) {
Expand All @@ -462,6 +473,8 @@ Domain.prototype = {
value: JSON.stringify(value)
}])
});

return this;
},
getConfiguration: function(key) {
if (!this.context)
Expand Down Expand Up @@ -489,6 +502,8 @@ Domain.prototype = {
table: this.configurationsTableName,
key: key
});

return this;
}
};

Expand Down
12 changes: 10 additions & 2 deletions lib/database/index-field.js
Expand Up @@ -285,9 +285,11 @@ IndexField.prototype = {
});

this.saveOptionsSync();

return this;
},
saveOptionsSync: function() {
if (!this.exists()) return;
if (!this.exists()) return this;

this.facetEnabled;
if (this._facetEnabled !== undefined)
Expand All @@ -308,6 +310,8 @@ IndexField.prototype = {
this.domain.defaultSearchField = this._defaultSearchField ? this : null ;
delete this._defaultSearchField;
}

return this;
},
deleteSync: function() {
// backup information for re-creation
Expand All @@ -332,6 +336,8 @@ IndexField.prototype = {
this.domain.deleteConfiguration(this.searchEnabledConfigurationKey);
if (this._defaultSearchField)
this.domain.defaultSearchField = null;

return this;
},
reindexSync: function() {
var name = this.name;
Expand Down Expand Up @@ -369,18 +375,20 @@ IndexField.prototype = {
source: this.columnName
});
}
return this;
},

exists: function() {
return !!this.column;
},

upgradeToMultipleValuesSync: function() {
if (this.multipleValues) return;
if (this.multipleValues) return this;
var values = this.domain.dumpSync();
this.deleteSync();
this.createSync(true);
this.domain.loadSync(values);
return this;
}
};

Expand Down

0 comments on commit b194840

Please sign in to comment.