null+****@clear*****
null+****@clear*****
2012年 7月 11日 (水) 19:04:04 JST
SHIMODA Hiroshi 2012-07-11 19:04:04 +0900 (Wed, 11 Jul 2012) New Revision: 96104e05cc8b5905e746d1ef1c3dd07aee616be0 https://github.com/groonga/gcs/commit/96104e05cc8b5905e746d1ef1c3dd07aee616be0 Log: Replace Processor#getColumns by Processor#getIndexFields Modified files: lib/batch/processor.js test/batch-processor.test.js Modified: lib/batch/processor.js (+13 -13) =================================================================== --- lib/batch/processor.js 2012-07-11 18:59:10 +0900 (63aec1c) +++ lib/batch/processor.js 2012-07-11 19:04:04 +0900 (3a2a615) @@ -19,21 +19,21 @@ Processor.prototype = { this.database = new Database(this.database || this.databasePath); this.translator = new translator.Translator(this.domain); }, - getColumns: function() { + getIndexFields: function() { var self = this; - if (this._columns) { - return self._columns; + if (this._indexFields) { + return self._indexFields; } else { - var columns = this.database.ordinalColumnsSync(this.translator.tableName); - return this._columns = columns; + var fields = this.database.indexFieldsSync(this.domain.name); + return this._indexFields = fields; } }, validate: function(batches) { - var columns = this.getColumns(); + var fields = this.getIndexFields(); var errors = []; batches.forEach(function(batch) { if (batch.type == 'add') { - errors = errors.concat(this.validateAddBatch(batch, columns)); + errors = errors.concat(this.validateAddBatch(batch, fields)); } }, this); if (errors.length) { @@ -43,14 +43,14 @@ Processor.prototype = { throw error; } }, - validateAddBatch: function(batch, columns) { + validateAddBatch: function(batch, fields) { if (!batch.fields) { return [batch.id + ': You must specify "fields".']; } - var column; - var columnNames = columns.map(function(column) { - return column.name; + var fieldName; + var fieldNames = fields.map(function(field) { + return field.name; }); var fieldsCount = 0; var errors = []; @@ -61,13 +61,13 @@ Processor.prototype = { fieldsCount++; try { - column = this.domain.getIndexField(field).columnName; + fieldName = this.domain.getIndexField(field).name; } catch(error) { errors.push(batch.id + ': ' + error.message); continue; } - if (columnNames.indexOf(column) < 0) + if (fieldNames.indexOf(fieldName) < 0) errors.push(batch.id + ': The field "' + field + '" is unknown.'); if (batch.fields[field] === null) Modified: test/batch-processor.test.js (+24 -61) =================================================================== --- test/batch-processor.test.js 2012-07-11 18:59:10 +0900 (9714c97) +++ test/batch-processor.test.js 2012-07-11 19:04:04 +0900 (2f0f82d) @@ -46,69 +46,32 @@ suite('batch/processor/Processor (instance methods)', function() { assert.equal(processor.databasePath, temporaryDatabase.path); }); - test('getColumns', function() { - var columns = processor.getColumns(); + test('getIndexFields', function() { + var fields = processor.getIndexFields(); var expected = [ - { id: 0, - name: 'address', - path: '/path/to/database/file', - type: 'var', - flags: + { name: 'address', + columnName: 'address', + type: 'text'}, + { name: 'age', + columnName: 'age', + type: 'uint'}, + { name: 'description', + columnName: 'description', + type: 'text'}, + { name: 'email_address', + columnName: 'email_address', + type: 'text'}, + { name: 'name', + columnName: 'name', + type: 'text'}, + { name: 'product', + columnName: 'product', + type: 'literal'} ]; - - - -[ { id: 265, - name: 'address', - path: '/home/piro/gcs/test/tmp/database-1/database.0000109', - type: 'var', - flags: 'COLUMN_SCALAR|PERSISTENT', - domain: 'companies', - range: 'ShortText', - source: [] }, - { id: 271, - name: 'age', - path: '/home/piro/gcs/test/tmp/database-1/database.000010F', - type: 'fix', - flags: 'COLUMN_SCALAR|PERSISTENT', - domain: 'companies', - range: 'UInt32', - source: [] }, - { id: 264, - name: 'description', - path: '/home/piro/gcs/test/tmp/database-1/database.0000108', - type: 'var', - flags: 'COLUMN_SCALAR|PERSISTENT', - domain: 'companies', - range: 'ShortText', - source: [] }, - { id: 266, - name: 'email_address', - path: '/home/piro/gcs/test/tmp/database-1/database.000010A', - type: 'var', - flags: 'COLUMN_SCALAR|PERSISTENT', - domain: 'companies', - range: 'ShortText', - source: [] }, - { id: 263, - name: 'name', - path: '/home/piro/gcs/test/tmp/database-1/database.0000107', - type: 'var', - flags: 'COLUMN_SCALAR|PERSISTENT', - domain: 'companies', - range: 'ShortText', - source: [] }, - { id: 267, - name: 'product', - path: '/home/piro/gcs/test/tmp/database-1/database.000010B', - type: 'fix', - flags: 'COLUMN_SCALAR|PERSISTENT', - domain: 'companies', - range: 'companies_product', - source: [] } ] - - - assert.deepEqual(columns.sort(), expected.sort()); + function sortFields(a, b) { + return a.name - b.name; + } + assert.deepEqual(fields.sort(sortFields), expected.sort(sortFields)); }); test('load add-batches', function(done) { -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... 다운로드