mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
34 lines
856 B
Go
34 lines
856 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package mysql
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
)
|
|
|
|
// Tables retrieves and returns the tables of current schema.
|
|
// 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
|
|
link, err := d.SlaveLink(schema...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result, err = d.DoSelect(ctx, link, `SHOW TABLES`)
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, m := range result {
|
|
for _, v := range m {
|
|
tables = append(tables, v.String())
|
|
}
|
|
}
|
|
return
|
|
}
|