Add context support for orm

Signed-off-by: Penghui Liao <liaoishere@gmail.com>
This commit is contained in:
Penghui Liao
2021-01-08 19:04:00 +08:00
parent c603131436
commit 21777d3143
15 changed files with 215 additions and 175 deletions

View File

@@ -15,6 +15,7 @@
package orm
import (
"context"
"flag"
"fmt"
"os"
@@ -76,6 +77,7 @@ func RunCommand() {
// sync database struct command interface.
type commandSyncDb struct {
ctx context.Context
al *alias
force bool
verbose bool
@@ -154,7 +156,7 @@ func (d *commandSyncDb) Run() error {
}
var fields []*fieldInfo
columns, err := d.al.DbBaser.GetColumns(db, mi.table)
columns, err := d.al.DbBaser.GetColumns(d.ctx, db, mi.table)
if err != nil {
if d.rtOnError {
return err
@@ -188,7 +190,7 @@ func (d *commandSyncDb) Run() error {
}
for _, idx := range indexes[mi.table] {
if !d.al.DbBaser.IndexExists(db, idx.Table, idx.Name) {
if !d.al.DbBaser.IndexExists(d.ctx, db, idx.Table, idx.Name) {
if !d.noInfo {
fmt.Printf("create index `%s` for table `%s`\n", idx.Name, idx.Table)
}
@@ -290,6 +292,7 @@ func RunSyncdb(name string, force bool, verbose bool) error {
al := getDbAlias(name)
cmd := new(commandSyncDb)
cmd.ctx = context.TODO()
cmd.al = al
cmd.force = force
cmd.noInfo = !verbose