notes/brainstorming.txt
[app.Builder.js] / dbgenerate.js
index 790707b..5d2d001 100644 (file)
@@ -118,15 +118,21 @@ Gda.DataSelect.prototype.fetchAll = function()
 var map = {
     'date' : 'date',
     'datetime' : 'date',
+    'timestamp with time zone' : 'date',
+    'timestamp without time zone' : 'date',
     'time' : 'string', //bogus
     'int' : 'int',
+    'integer' : 'int',
     'bigint' : 'int',
     'double' : 'float',
     'tinyint' : 'int',
     'smallint' : 'int',
     'decimal' : 'float',
     'float' : 'float',
+    'numeric' : 'float',
     'char' : 'string',
+    'character' : 'string',
+    'character varying' : 'string',
     'varchar' : 'string',
     'text' : 'string',
     'longtext' : 'string',
@@ -134,7 +140,10 @@ var map = {
     'mediumtext' : 'string',
     'enum' : 'string',
     'timestamp' : 'number',
-    'blob' : 'text'
+    'blob' : 'text',
+    'bytea' : 'text',
+    'boolean' : 'int',
+    'text[]' : 'string',
     
 }
 
@@ -238,8 +247,12 @@ switch(cfg.DBTYPE) {
             "WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast')" +
             "AND pg_catalog.pg_table_is_visible(c.oid) ";
          query_describe_table =  
-                "SELECT f.attnum AS number, f.attname AS name, f.attnum, " +
-                "f.attnotnull AS notnull, pg_catalog.format_type(f.atttypid,f.atttypmod) AS type, " +
+                "SELECT " +
+                "f.attnum AS number, " +
+                "f.attname AS Field, " +
+                "f.attnum, " +
+                "CASE WHEN f.attnotnull = 't' THEN 'NO' ELSE 'YES' END AS isNull, " + 
+                "pg_catalog.format_type(f.atttypid,f.atttypmod) AS Type, " +
                 "CASE WHEN p.contype = 'p' THEN 't' ELSE 'f' END AS primarykey, " +
                 "CASE WHEN p.contype = 'u' THEN 't' ELSE 'f' END AS uniquekey, " +
                 "CASE WHEN p.contype = 'f' THEN g.relname END AS foreignkey, " +
@@ -259,10 +272,12 @@ switch(cfg.DBTYPE) {
                 
                 
         break;
+    default:
+        throw "Invalid data base type " + cfg.DBTYPE + " should be MySQL or PostgreSQL";
 /*
            "Field": "province",
         "Type": "varchar(255)",
-        "Null": "NO",
+        "Null": "NO", << or is null
         "Key": null,
         "Default": null,
         "Extra": 
@@ -291,10 +306,12 @@ tables.forEach(function(table) {
        
     var firstTxtCol = '';
     
-    print(JSON.stringify(schema, null,4));
-    Seed.quit();
+    //print(JSON.stringify(schema, null,4));    Seed.quit();
     
     schema.forEach(function(e)  {
+        e.Type = e.Type || e.type;
+        e.Field = e.Field || e.field;
+         
         var type = e.Type.match(/([^(]+)\(([^\)]+)\)/);
         var row  = { }; 
         if (type) {
@@ -345,6 +362,8 @@ tables.forEach(function(table) {
             "*prop": "colModel[]"
         });
         var xtype = 'TextField';
+        
+        
         if (row.type == 'number') {
             xtype = 'NumberField';
         }
@@ -368,6 +387,11 @@ tables.forEach(function(table) {
             '|xns' : 'Roo.form',
             xtype : xtype
         }
+         if (xtype == 'DateField') {
+            form[row.name].format = 'Y-m-d';
+            form[row.name].width = 100;
+        }
+        
         if (xtype == 'TextArea') {
             form[row.name].height = 100;
         }
@@ -381,8 +405,8 @@ tables.forEach(function(table) {
     var combo = {
         '|xns' : 'Roo.form',
         xtype: 'ComboBox',
-        allowBlank : 'false',
-        editable : 'false',
+        allowBlank : false,
+        editable : false,
         emptyText : 'Select ' + table,
         forceSelection : true,
         listWidth : 400,
@@ -602,7 +626,7 @@ readers.forEach(function(reader) {
                         "|rowdblclick": "function (_self, rowIndex, e)\n" + 
                             "{\n" + 
                             "    if (!_this.dialog) return;\n" + 
-                            "    _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {\n" + 
+                            "    _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {\n" + 
                             "        _this.grid.footer.onClick('first');\n" + 
                             "    }); \n" + 
                             "}\n"
@@ -833,6 +857,7 @@ readers.forEach(function(reader) {
             "resizable": false,
             "title": "Edit / Create " + reader.table,
             "width": 400,
+            "modal" : true,
             "xtype": "LayoutDialog",
             "|xns": "Roo",
             "items": [