X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=dbgenerate.js;h=0ea16fda806638b796beb905bec622c88ae15d72;hb=119290bc3234e9ece1c64dbd72ca486d9633b5b7;hp=360c42508ed65c81f58f7c77b21ebca440041174;hpb=adecff6d16c8ed27ebef63102a57f3dc3dd68e9a;p=app.Builder.js diff --git a/dbgenerate.js b/dbgenerate.js index 360c42508..0ea16fda8 100644 --- a/dbgenerate.js +++ b/dbgenerate.js @@ -55,7 +55,7 @@ var o = new Options({ { arg_long : 'DBTYPE' , arg_short : 't', description : 'Database Type (eg. MySQL or PostgreSQL ' }, { arg_long : 'DBNAME' , arg_short : 'd', description : 'Database Name' }, { arg_long : 'USERNAME' , arg_short : 'u', description : 'Username'}, - { arg_long : 'PASSWORD' , arg_short : 'p', description : '' , arg_default :'' }, + { arg_long : 'PASSWORD' , arg_short : 'p', description : 'Password' , arg_default :'' }, { arg_long : 'INI' , arg_short : 'I', description : 'Either base directory which has Pman/***/DataObjects/***.links.ini or location of ini 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', } @@ -150,16 +159,22 @@ function readIni(fn) var groups = key_file.get_groups(); groups.forEach(function(g) { + //print("KEY:"+g); ini[g] = {} - print("KEY:"+g); + var keys = key_file.get_keys(g); if (!keys) { return; } - keys.forEach(function(k) { - ini[g][k] = key_file.get_value(g,k); - }) - }) - + + keys.forEach(function(k) { + print("GET val: " + k); + ini[g][k] = key_file.get_value(g,k); + print(ini[g][k] ); + }); + //print("DONE KEY:"+g); + }); + //print("DONE KEYS"); } + if (File.isFile(cfg.INI)) { if (cfg.INI.match(/links\.ini$/)) { readIni(cfg.INI); @@ -219,7 +234,7 @@ if (File.isDirectory(cfg.INI)) { } //print(JSON.stringify(ini, null,4)); //console.dump(ini); - +print("DONE INI"); //Seed.quit(); @@ -237,16 +252,42 @@ switch(cfg.DBTYPE) { "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " + "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 " + - "attname as Field, " + - ", opcname , atttypmod " + - "FROM pg_attribute,pg_type, pg_opclass " + - " WHERE attrelid=typrelid AND atttypid=opcdeftype AND typname= '%s' "; + query_describe_table = + "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, " + + "CASE WHEN p.contype = 'f' THEN p.confkey END AS foreignkey_fieldnum, " + + "CASE WHEN p.contype = 'f' THEN g.relname END AS foreignkey, " + + "CASE WHEN p.contype = 'f' THEN p.conkey END AS foreignkey_connnum, " + + "CASE WHEN f.atthasdef = 't' THEN d.adsrc END AS default " + + "FROM pg_attribute f JOIN pg_class c ON c.oid = f.attrelid " + + " JOIN pg_type t ON t.oid = f.atttypid " + + " LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum " + + " LEFT JOIN pg_namespace n ON n.oid = c.relnamespace " + + " LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY ( p.conkey ) " + + " LEFT JOIN pg_class AS g ON p.confrelid = g.oid " + + "WHERE c.relkind = 'r'::char AND n.nspname = '%n' " + + "AND c.relname = '%s' AND f.attnum > 0 ORDER BY number"; + + + break; + default: + throw { + name: "ArgumentError", + message: "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": @@ -256,14 +297,15 @@ switch(cfg.DBTYPE) { -var tables = Gda.execute_select_command(cnc, query_tables).fetchAll(); +var tables = cnc.execute_select_command( query_tables).fetchAll(); print(JSON.stringify(tables)); var readers = []; tables.forEach(function(table) { //print(table); - var schema = Gda.execute_select_command(cnc, - query_describe_table.replace(/%s/, table) ).fetchAll(); + var schema = cnc.execute_select_command( + query_describe_table.replace(/%s/, table).replace(/%n/,'public') + ).fetchAll(); var reader = []; @@ -274,10 +316,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) { @@ -328,6 +372,8 @@ tables.forEach(function(table) { "*prop": "colModel[]" }); var xtype = 'TextField'; + + if (row.type == 'number') { xtype = 'NumberField'; } @@ -351,6 +397,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; } @@ -364,8 +415,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, @@ -585,7 +636,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" @@ -816,6 +867,7 @@ readers.forEach(function(reader) { "resizable": false, "title": "Edit / Create " + reader.table, "width": 400, + "modal" : true, "xtype": "LayoutDialog", "|xns": "Roo", "items": [