|
@@ -764,13 +764,18 @@ var (
|
|
|
"YES": true,
|
|
"YES": true,
|
|
|
"ZONE": true,
|
|
"ZONE": true,
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // DefaultPostgresSchema default postgres schema
|
|
|
|
|
+ DefaultPostgresSchema = "public"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type postgres struct {
|
|
type postgres struct {
|
|
|
core.Base
|
|
core.Base
|
|
|
|
|
+ schema string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (db *postgres) Init(d *core.DB, uri *core.Uri, drivername, dataSourceName string) error {
|
|
func (db *postgres) Init(d *core.DB, uri *core.Uri, drivername, dataSourceName string) error {
|
|
|
|
|
+ db.schema = DefaultPostgresSchema
|
|
|
return db.Base.Init(d, db, uri, drivername, dataSourceName)
|
|
return db.Base.Init(d, db, uri, drivername, dataSourceName)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -928,7 +933,7 @@ func (db *postgres) IsColumnExist(tableName, colName string) (bool, error) {
|
|
|
|
|
|
|
|
func (db *postgres) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
|
|
func (db *postgres) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
|
|
|
// FIXME: the schema should be replaced by user custom's
|
|
// FIXME: the schema should be replaced by user custom's
|
|
|
- args := []interface{}{tableName, "public"}
|
|
|
|
|
|
|
+ args := []interface{}{tableName, db.schema}
|
|
|
s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_precision_radix ,
|
|
s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_precision_radix ,
|
|
|
CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey,
|
|
CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey,
|
|
|
CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey
|
|
CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey
|
|
@@ -1029,8 +1034,7 @@ WHERE c.relkind = 'r'::char AND c.relname = $1 AND s.table_schema = $2 AND f.att
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (db *postgres) GetTables() ([]*core.Table, error) {
|
|
func (db *postgres) GetTables() ([]*core.Table, error) {
|
|
|
- // FIXME: replace public to user customrize schema
|
|
|
|
|
- args := []interface{}{"public"}
|
|
|
|
|
|
|
+ args := []interface{}{db.schema}
|
|
|
s := fmt.Sprintf("SELECT tablename FROM pg_tables WHERE schemaname = $1")
|
|
s := fmt.Sprintf("SELECT tablename FROM pg_tables WHERE schemaname = $1")
|
|
|
db.LogSQL(s, args)
|
|
db.LogSQL(s, args)
|
|
|
|
|
|
|
@@ -1055,8 +1059,7 @@ func (db *postgres) GetTables() ([]*core.Table, error) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error) {
|
|
func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error) {
|
|
|
- // FIXME: replace the public schema to user specify schema
|
|
|
|
|
- args := []interface{}{"public", tableName}
|
|
|
|
|
|
|
+ args := []interface{}{db.schema, tableName}
|
|
|
s := fmt.Sprintf("SELECT indexname, indexdef FROM pg_indexes WHERE schemaname=$1 AND tablename=$2")
|
|
s := fmt.Sprintf("SELECT indexname, indexdef FROM pg_indexes WHERE schemaname=$1 AND tablename=$2")
|
|
|
db.LogSQL(s, args)
|
|
db.LogSQL(s, args)
|
|
|
|
|
|