add progress bar
This commit is contained in:
parent
39e0e4344f
commit
6fa443d62b
3 changed files with 44 additions and 4 deletions
15
app/app.go
15
app/app.go
|
|
@ -7,6 +7,8 @@ import (
|
|||
|
||||
"strings"
|
||||
|
||||
"github.com/schollz/progressbar/v3"
|
||||
|
||||
"gitnet.fr/deblan/database-anonymizer/config"
|
||||
"gitnet.fr/deblan/database-anonymizer/data"
|
||||
"gitnet.fr/deblan/database-anonymizer/database"
|
||||
|
|
@ -42,9 +44,13 @@ func (a *App) Run(
|
|||
}
|
||||
|
||||
func (a *App) TruncateTable(c config.SchemaConfigAction) error {
|
||||
bar := progressbar.Default(1, fmt.Sprintf("Truncating %s...", c.Table))
|
||||
|
||||
if c.Query == "" {
|
||||
_, err := a.Db.Exec(fmt.Sprintf("TRUNCATE %s", database.EscapeTable(a.DbConfig.Type, c.Table)))
|
||||
|
||||
bar.Add(1)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -52,6 +58,8 @@ func (a *App) TruncateTable(c config.SchemaConfigAction) error {
|
|||
rows := database.GetRows(a.Db, query, c.Table, a.DbConfig.Type)
|
||||
var scan any
|
||||
|
||||
bar.ChangeMax(len(rows))
|
||||
|
||||
for _, row := range rows {
|
||||
pkeys := []string{}
|
||||
values := make(map[int]string)
|
||||
|
|
@ -80,6 +88,8 @@ func (a *App) TruncateTable(c config.SchemaConfigAction) error {
|
|||
}
|
||||
|
||||
a.Db.QueryRow(sql, args...).Scan(&scan)
|
||||
|
||||
bar.Add(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -90,6 +100,9 @@ func (a *App) UpdateRows(c config.SchemaConfigAction, globalColumns map[string]s
|
|||
rows := database.GetRows(a.Db, query, c.Table, a.DbConfig.Type)
|
||||
var scan any
|
||||
|
||||
bar := progressbar.Default(int64(len(rows)))
|
||||
bar.Describe(fmt.Sprintf("Updating %s...", c.Table))
|
||||
|
||||
for key, row := range rows {
|
||||
if len(c.VirtualColumns) > 0 {
|
||||
for col, faker := range c.VirtualColumns {
|
||||
|
|
@ -194,6 +207,8 @@ func (a *App) UpdateRows(c config.SchemaConfigAction, globalColumns map[string]s
|
|||
logger.LogFatalExitIf(err)
|
||||
}
|
||||
}
|
||||
|
||||
bar.Add(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue