Navigation Menu

Skip to content

Commit

Permalink
Add mechanism to store configurations related to tables
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 13, 2012
1 parent 57e44f8 commit 94587fe
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/database/domain.js
Expand Up @@ -155,6 +155,10 @@ Domain.prototype = {
return this.indexTableBaseName + 'BigramTerms';
},

get configurationsTableName() {
return this.tableName + '_configurations';
},

get synonymsTableName() {
return this.tableName + '_synonyms';
},
Expand Down Expand Up @@ -225,6 +229,19 @@ Domain.prototype = {
flags: nroonga.TABLE_HASH_KEY,
key_type: nroonga.ShortText
});

this.context.commandSync('table_create', {
name: this.configurationsTableName,
flags: nroonga.TABLE_HASH_KEY,
key_type: nroonga.ShortText
});
this.context.commandSync('column_create', {
table: this.configurationsTableName,
name: 'value',
type: nroonga.ShortText,
flags: nroonga.COLUMN_SCALAR
});

this.context.commandSync('table_create', {
name: this.termsTableName,
flags: nroonga.TABLE_PAT_KEY + '|' + nroonga.KEY_NORMALIZE,
Expand All @@ -240,6 +257,9 @@ Domain.prototype = {
this.context.commandSync('table_remove', {
name: this.tableName
});
this.context.commandSync('table_remove', {
name: this.configurationsTableName
});
this.context.commandSync('table_remove', {
name: this.termsTableName
});
Expand Down Expand Up @@ -380,6 +400,38 @@ Domain.prototype = {
table: this.tableName,
key: id
});
},

setConfiguration: function(key, value) {
this.context.commandSync('load', {
table: this.configurationsTableName,
values: JSON.stringify([{
_key: key,
value: JSON.stringify(value)
}])
});
},
getConfiguration: function(key) {
var options = {
table: this.configurationsTableName,
limit: -1,
offset: 0,
query: '_key=' + key,
output_columns: '_key,value'
};
var values = this.context.commandSync('select', options);
values = nroonga.formatSelectResult(values);
if (values.count == 0)
return undefined;

var value = values.results[key]['value'];
return JSON.parse(value);
},
deleteConfiguration: function(key) {
this.context.commandSync('delete', {
table: this.configurationsTableName,
key: key
});
}
};

Expand Down

0 comments on commit 94587fe

Please sign in to comment.