mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
allow any schema in PostgresDB;
如果选择 PostgreSQL,允许定制的 schema;
This commit is contained in:
parent
76eb064e69
commit
6481a96ca4
17
g_appcode.go
17
g_appcode.go
@ -516,7 +516,9 @@ func (*MysqlDB) GetGoDataType(sqlType string) (goType string) {
|
|||||||
func (*PostgresDB) GetTableNames(db *sql.DB) (tables []string) {
|
func (*PostgresDB) GetTableNames(db *sql.DB) (tables []string) {
|
||||||
rows, err := db.Query(`
|
rows, err := db.Query(`
|
||||||
SELECT table_name FROM information_schema.tables
|
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 {
|
if err != nil {
|
||||||
ColorLog("[ERRO] Could not show tables: %s\n", err)
|
ColorLog("[ERRO] Could not show tables: %s\n", err)
|
||||||
ColorLog("[HINT] Check your connection string\n")
|
ColorLog("[HINT] Check your connection string\n")
|
||||||
@ -551,8 +553,10 @@ func (*PostgresDB) GetConstraints(db *sql.DB, table *Table, blackList map[string
|
|||||||
INNER JOIN
|
INNER JOIN
|
||||||
information_schema.constraint_column_usage cu ON cu.constraint_name = c.constraint_name
|
information_schema.constraint_column_usage cu ON cu.constraint_name = c.constraint_name
|
||||||
WHERE
|
WHERE
|
||||||
c.table_catalog = current_database() AND c.table_schema = 'public' AND c.table_name = $1
|
c.table_catalog = current_database() AND c.table_schema NOT IN ('pg_catalog', 'information_schema')
|
||||||
AND u.table_catalog = current_database() AND u.table_schema = 'public' AND u.table_name = $2`,
|
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,
|
table.Name, table.Name) // u.position_in_unique_constraint,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ColorLog("[ERRO] Could not query INFORMATION_SCHEMA for PK/UK/FK information: %s\n", err)
|
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
|
FROM
|
||||||
information_schema.columns
|
information_schema.columns
|
||||||
WHERE
|
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)
|
table.Name)
|
||||||
defer colDefRows.Close()
|
defer colDefRows.Close()
|
||||||
for colDefRows.Next() {
|
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)
|
ColorLog("[ERRO] Can't generate application code outside of GOPATH '%s'\n", gopath)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if curpath == appsrcpath {
|
if curpath == appsrcpath {
|
||||||
ColorLog("[ERRO] Can't generate application code outside of application PATH \n")
|
ColorLog("[ERRO] Can't generate application code outside of application PATH \n")
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
packpath = strings.Join(strings.Split(curpath[len(appsrcpath)+1:], string(filepath.Separator)), "/")
|
packpath = strings.Join(strings.Split(curpath[len(appsrcpath)+1:], string(filepath.Separator)), "/")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user