[Groonga-commit] groonga/gcs [master] Set default value of uint index field to 0 on creation

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 22 18:22:16 JST 2012


YUKI Hiroshi	2012-11-22 18:22:16 +0900 (Thu, 22 Nov 2012)

  New Revision: ad696b50ba7b7d26603be26a537a2567f6bf3038
  https://github.com/groonga/gcs/commit/ad696b50ba7b7d26603be26a537a2567f6bf3038

  Log:
    Set default value of uint index field to 0 on creation

  Modified files:
    lib/database/index-field.js

  Modified: lib/database/index-field.js (+14 -3)
===================================================================
--- lib/database/index-field.js    2012-11-22 18:10:44 +0900 (50a7276)
+++ lib/database/index-field.js    2012-11-22 18:22:16 +0900 (64ae14d)
@@ -346,9 +346,15 @@ IndexField.prototype = {
 
 
   get defaultValue() {
-    if (this.type == 'uint')
-      return 0;
-    return null;
+    var value = this.getOption('defaultValue');
+    return this.type == 'uint' ? parseInt(value || 0) : value;
+  },
+  set defaultValue(value) {
+    return this.setOption('defaultValue', value);
+  },
+  setDefaultValue: function(value) {
+    this.defaultValue = value;
+    return this;
   },
   get hasDefaultValue() {
     return this.hasOption('defaultValue');
@@ -548,6 +554,11 @@ IndexField.prototype = {
       source: this.columnName
     });
 
+    if (this.type == 'uint' && !this.hasDefaultValue) {
+      this.defaultValue = 0;
+      this.saveOptions();
+    }
+
     var now = new Date();
     if (!this._createdAt) {
       this.updatedAt = this.createdAt = now;
-------------- next part --------------
HTML����������������������������...
Descargar 



More information about the Groonga-commit mailing list
Back to archive index