SHIMODA Hiroshi
null+****@clear*****
Mon Aug 13 16:04:50 JST 2012
SHIMODA Hiroshi 2012-08-13 16:04:50 +0900 (Mon, 13 Aug 2012) New Revision: 94587fe08134be79cb22dc57e3c38ba808441883 https://github.com/groonga/gcs/commit/94587fe08134be79cb22dc57e3c38ba808441883 Log: Add mechanism to store configurations related to tables Modified files: lib/database/domain.js Modified: lib/database/domain.js (+52 -0) =================================================================== --- lib/database/domain.js 2012-08-13 17:06:58 +0900 (ddb5efa) +++ lib/database/domain.js 2012-08-13 16:04:50 +0900 (965ab4a) @@ -155,6 +155,10 @@ Domain.prototype = { return this.indexTableBaseName + 'BigramTerms'; }, + get configurationsTableName() { + return this.tableName + '_configurations'; + }, + get synonymsTableName() { return this.tableName + '_synonyms'; }, @@ -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, @@ -241,6 +258,9 @@ Domain.prototype = { name: this.tableName }); this.context.commandSync('table_remove', { + name: this.configurationsTableName + }); + this.context.commandSync('table_remove', { name: this.termsTableName }); }, @@ -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 + }); } }; -------------- next part -------------- HTML����������������������������...Download