From 6481a96ca4506c769f1c6b1794d32f6c91237aa0 Mon Sep 17 00:00:00 2001 From: Liut Date: Fri, 11 Mar 2016 23:39:17 +0800 Subject: [PATCH] =?UTF-8?q?allow=20any=20schema=20in=20PostgresDB;=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E9=80=89=E6=8B=A9=20PostgreSQL=EF=BC=8C?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=AE=9A=E5=88=B6=E7=9A=84=20schema;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g_appcode.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/g_appcode.go b/g_appcode.go index f5f6b0d..7860912 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -516,7 +516,9 @@ func (*MysqlDB) GetGoDataType(sqlType string) (goType string) { func (*PostgresDB) GetTableNames(db *sql.DB) (tables []string) { rows, err := db.Query(` SELECT table_name FROM information_schema.tables - WHERE table_catalog = current_database() and table_schema = 'public'`) + WHERE table_catalog = current_database() AND + table_type = 'BASE TABLE' AND + table_schema NOT IN ('pg_catalog', 'information_schema')`) if err != nil { ColorLog("[ERRO] Could not show tables: %s\n", err) ColorLog("[HINT] Check your connection string\n") @@ -551,8 +553,10 @@ func (*PostgresDB) GetConstraints(db *sql.DB, table *Table, blackList map[string INNER JOIN information_schema.constraint_column_usage cu ON cu.constraint_name = c.constraint_name WHERE - c.table_catalog = current_database() AND c.table_schema = 'public' AND c.table_name = $1 - AND u.table_catalog = current_database() AND u.table_schema = 'public' AND u.table_name = $2`, + c.table_catalog = current_database() AND c.table_schema NOT IN ('pg_catalog', 'information_schema') + AND c.table_name = $1 + AND u.table_catalog = current_database() AND u.table_schema NOT IN ('pg_catalog', 'information_schema') + AND u.table_name = $2`, table.Name, table.Name) // u.position_in_unique_constraint, if err != nil { ColorLog("[ERRO] Could not query INFORMATION_SCHEMA for PK/UK/FK information: %s\n", err) @@ -608,7 +612,8 @@ func (postgresDB *PostgresDB) GetColumns(db *sql.DB, table *Table, blackList map FROM information_schema.columns WHERE - table_catalog = current_database() AND table_schema = 'public' AND table_name = $1`, + table_catalog = current_database() AND table_schema NOT IN ('pg_catalog', 'information_schema') + AND table_name = $1`, table.Name) defer colDefRows.Close() for colDefRows.Next() { @@ -985,12 +990,12 @@ func getPackagePath(curpath string) (packpath string) { ColorLog("[ERRO] Can't generate application code outside of GOPATH '%s'\n", gopath) os.Exit(2) } - + if curpath == appsrcpath { ColorLog("[ERRO] Can't generate application code outside of application PATH \n") os.Exit(2) } - + packpath = strings.Join(strings.Split(curpath[len(appsrcpath)+1:], string(filepath.Separator)), "/") return }