mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue 1915 and repeated link instance key for package gdb (#2250)
* fix issue #1915 * fix issue in repeated link instance key * add configuration item Namespace for package gdb * up * up * fix: pgsql list table names (#2255) Co-authored-by: Gin <qinyuguang@gmail.com>
This commit is contained in:
@ -35,6 +35,7 @@ type Driver struct {
|
||||
|
||||
const (
|
||||
internalPrimaryKeyInCtx gctx.StrKey = "primary_key"
|
||||
defaultSchema = "public"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -222,9 +223,18 @@ func (d *Driver) DoFilter(ctx context.Context, link gdb.Link, sql string, args [
|
||||
// It's mainly used in cli tool chain for automatically generating the models.
|
||||
func (d *Driver) Tables(ctx context.Context, schema ...string) (tables []string, err error) {
|
||||
var (
|
||||
result gdb.Result
|
||||
querySchema = gutil.GetOrDefaultStr("public", schema...)
|
||||
query = fmt.Sprintf(`
|
||||
result gdb.Result
|
||||
usedSchema = gutil.GetOrDefaultStr(d.GetConfig().Namespace, schema...)
|
||||
)
|
||||
if usedSchema == "" {
|
||||
usedSchema = defaultSchema
|
||||
}
|
||||
// DO NOT use `usedSchema` as parameter for function `SlaveLink`.
|
||||
link, err := d.SlaveLink(schema...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var query = fmt.Sprintf(`
|
||||
SELECT
|
||||
c.relname
|
||||
FROM
|
||||
@ -235,16 +245,11 @@ WHERE
|
||||
n.nspname = '%s'
|
||||
AND c.relkind IN ('r', 'p')
|
||||
AND c.relpartbound IS NULL
|
||||
AND PG_TABLE_IS_VISIBLE(c.oid)
|
||||
ORDER BY
|
||||
c.relname`,
|
||||
querySchema,
|
||||
)
|
||||
usedSchema,
|
||||
)
|
||||
link, err := d.SlaveLink(schema...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
query, _ = gregex.ReplaceString(`[\n\r\s]+`, " ", gstr.Trim(query))
|
||||
result, err = d.DoSelect(ctx, link, query)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user