[Groonga-commit] groonga/gcs [master] Translate index field type to column type by Field class

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 9日 (月) 17:42:02 JST


SHIMODA Hiroshi	2012-07-09 17:42:02 +0900 (Mon, 09 Jul 2012)

  New Revision: 59e8897d496395baf858fa5612801be6b0ee415f
  https://github.com/groonga/gcs/commit/59e8897d496395baf858fa5612801be6b0ee415f

  Log:
    Translate index field type to column type by Field class

  Modified files:
    lib/api/2011-02-01/configuration.js
    lib/batch/translator.js
    lib/domain.js
    test/batch-translator.test.js
    test/domain.test.js

  Modified: lib/api/2011-02-01/configuration.js (+1 -1)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-07-09 17:01:47 +0900 (82e47cc)
+++ lib/api/2011-02-01/configuration.js    2012-07-09 17:42:02 +0900 (12ed28f)
@@ -205,7 +205,7 @@ handlers.DefineIndexField = function(database, request, response) {
   var field = domain.getIndexField(fieldName);
 
   var createdAt = new Date();
-  var columnType = Translator.translateIndexFieldType(fieldType);
+  var columnType = field.fieldTypeToColumnType(fieldType);
   try {
     database.commandSync('column_create', {
       table: domain.tableName,

  Modified: lib/batch/translator.js (+0 -13)
===================================================================
--- lib/batch/translator.js    2012-07-09 17:01:47 +0900 (ed4c9ed)
+++ lib/batch/translator.js    2012-07-09 17:42:02 +0900 (24f344c)
@@ -81,16 +81,3 @@ function commandsToString(commandSets) {
          }).join('\n');
 }
 exports.commandsToString = Translator.commandsToString = commandsToString;
-
-function translateIndexFieldType(type) {
-  switch (type) {
-    case 'text':
-      return Database.ShortText;
-    case 'uint':
-      return Database.UInt32;
-    default:
-      throw new Error('Unsupported index field type '+type);
-  }
-}
-exports.translateIndexFieldType =
-  Translator.translateIndexFieldType = translateIndexFieldType;

  Modified: lib/domain.js (+16 -0)
===================================================================
--- lib/domain.js    2012-07-09 17:01:47 +0900 (e1a2f65)
+++ lib/domain.js    2012-07-09 17:42:02 +0900 (21fe0db)
@@ -152,6 +152,22 @@ IndexField.prototype = {
     if (!this._indexColumnName)
       this._indexColumnName = this.domain.tableName + '_' + this.columnName;
     return this._indexColumnName;
+  },
+  get alterTableName() {
+    if (!this._alterTableName)
+      this._alterTableName = this.domain.tableName + '_' + this.columnName;
+    return this._alterTableName;
+  },
+  fieldTypeToColumnType: function(fieldType) {
+    switch (fieldType) {
+      case 'text':
+        return Database.ShortText;
+      case 'uint':
+        return Database.UInt32;
+      case 'literal':
+        return this.alterTableName;
+      default:
+        throw new Error('Unsupported index field type '+fieldType);
   }
 };
 

  Modified: test/batch-translator.test.js (+0 -12)
===================================================================
--- test/batch-translator.test.js    2012-07-09 17:01:47 +0900 (4c024d2)
+++ test/batch-translator.test.js    2012-07-09 17:42:02 +0900 (4724b0d)
@@ -205,16 +205,4 @@ suite('batch/translator/Translator (class methods)', function() {
       assert.equal(stringified, expected);
     });
   });
-
-  suite('translateIndexFieldType', function() {
-    test('text', function() {
-      assert.equal(Translator.translateIndexFieldType('text'),
-                   'ShortText');
-    });
-
-    test('uint', function() {
-      assert.equal(Translator.translateIndexFieldType('uint'),
-                   'UInt32');
-    });
-  });
 });

  Modified: test/domain.test.js (+18 -0)
===================================================================
--- test/domain.test.js    2012-07-09 17:01:47 +0900 (206e94e)
+++ test/domain.test.js    2012-07-09 17:42:02 +0900 (6a0e60d)
@@ -183,5 +183,23 @@ suite('domain', function() {
       var field = new IndexField('valid_123', domain);
       assert.equal(field.indexColumnName, 'testdomain_valid_123');
     });
+
+    test('fieldTypeToColumnType (text)', function() {
+      var field = new IndexField('valid_123', domain);
+      assert.equal(field.fieldTypeToColumnType('text'),
+                   'ShortText');
+    });
+
+    test('fieldTypeToColumnType (uint)', function() {
+      var field = new IndexField('valid_123', domain);
+      assert.equal(field.fieldTypeToColumnType('uint'),
+                   'UInt32');
+    });
+
+    test('fieldTypeToColumnType (literal)', function() {
+      var field = new IndexField('valid_123', domain);
+      assert.equal(field.fieldTypeToColumnType('literal'),
+                   domain.tableName + '_valid_123');
+    });
   });
 });
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index