Skip to content

Commit

Permalink
fix(bundebug): change WithVerbose to accept a bool flag
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Oct 11, 2021
1 parent e621318 commit b2f8b91
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
sqlite.SetMaxOpenConns(1)

db := bun.NewDB(sqlite, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

// Register models for the fixture.
db.RegisterModel((*User)(nil), (*Story)(nil))
Expand Down
2 changes: 1 addition & 1 deletion example/belongs-to/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
db := bun.NewDB(sqldb, sqlitedialect.New())
defer db.Close()

db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

if err := createSchema(ctx, db); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion example/create-table-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
sqlite.SetMaxOpenConns(1)

db := bun.NewDB(sqlite, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

if _, err := db.NewCreateTable().Model((*Book)(nil)).Exec(ctx); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion example/fixture/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
sqldb.SetMaxOpenConns(1)

db := bun.NewDB(sqldb, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

// Register models before loading fixtures.
db.RegisterModel((*User)(nil), (*Org)(nil))
Expand Down
2 changes: 1 addition & 1 deletion example/has-many/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
db := bun.NewDB(sqldb, sqlitedialect.New())
defer db.Close()

db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

if err := createSchema(ctx, db); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion example/has-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
db := bun.NewDB(sqldb, sqlitedialect.New())
defer db.Close()

db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

if err := createSchema(ctx, db); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion example/many-to-many/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
db := bun.NewDB(sqldb, sqlitedialect.New())
defer db.Close()

db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

// Register many to many model so bun can better recognize m2m relation.
// This should be done before you use the model for the first time.
Expand Down
2 changes: 1 addition & 1 deletion example/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
}

db := bun.NewDB(sqldb, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

app := &cli.App{
Name: "bun",
Expand Down
2 changes: 1 addition & 1 deletion example/model-hooks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
sqlite.SetMaxOpenConns(1)

db := bun.NewDB(sqlite, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

// Register models for the fixture.
db.RegisterModel((*User)(nil), (*Story)(nil))
Expand Down
2 changes: 1 addition & 1 deletion example/opentelemetry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {

db := bun.NewDB(sqlite, sqlitedialect.New())
db.AddQueryHook(bunotel.NewQueryHook())
// db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
// db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

if _, err := db.NewCreateTable().Model((*TestModel)(nil)).Exec(ctx); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion example/pg-faceted-search/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))

db := bun.NewDB(sqldb, pgdialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

// Register models for the fixture.
db.RegisterModel((*Book)(nil))
Expand Down
2 changes: 1 addition & 1 deletion example/placeholders/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
sqlite.SetMaxOpenConns(1)

db := bun.NewDB(sqlite, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

var tableName, tableAlias, pks, tablePKs, columns, tableColumns string

Expand Down
2 changes: 1 addition & 1 deletion example/trivial/mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
db := bun.NewDB(sqldb, mysqldialect.New())

// Print all queries to stdout.
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

var rnd float64

Expand Down
2 changes: 1 addition & 1 deletion example/trivial/postgres/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
db := bun.NewDB(pgdb, pgdialect.New())

// Print all queries to stdout.
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

var rnd float64

Expand Down
2 changes: 1 addition & 1 deletion example/trivial/sqlite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
db := bun.NewDB(sqlite, sqlitedialect.New())

// Print all queries to stdout.
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

var rnd int64

Expand Down
2 changes: 1 addition & 1 deletion example/tx-composition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
sqlite.SetMaxOpenConns(1)

db := bun.NewDB(sqlite, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))

if err := db.ResetModel(ctx, (*User)(nil), (*Profile)(nil)); err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions extra/bundebug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

type ConfigOption func(*QueryHook)

func WithVerbose() ConfigOption {
func WithVerbose(on bool) ConfigOption {
return func(h *QueryHook) {
h.verbose = true
h.verbose = on
}
}

Expand Down
12 changes: 6 additions & 6 deletions internal/dbtest/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func pg(tb testing.TB) *bun.DB {
require.Equal(tb, "DB<dialect=pg>", db.String())

if _, ok := os.LookupEnv("DEBUG"); ok {
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
}

return db
Expand All @@ -85,7 +85,7 @@ func pgx(tb testing.TB) *bun.DB {
require.Equal(tb, "DB<dialect=pg>", db.String())

if _, ok := os.LookupEnv("DEBUG"); ok {
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
}

return db
Expand All @@ -107,7 +107,7 @@ func mysql8(tb testing.TB) *bun.DB {
require.Equal(tb, "DB<dialect=mysql>", db.String())

if _, ok := os.LookupEnv("DEBUG"); ok {
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
}

return db
Expand All @@ -129,7 +129,7 @@ func mysql5(tb testing.TB) *bun.DB {
require.Equal(tb, "DB<dialect=mysql>", db.String())

if _, ok := os.LookupEnv("DEBUG"); ok {
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
}

return db
Expand All @@ -151,7 +151,7 @@ func mariadb(tb testing.TB) *bun.DB {
require.Equal(tb, "DB<dialect=mysql>", db.String())

if _, ok := os.LookupEnv("DEBUG"); ok {
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
}

return db
Expand All @@ -168,7 +168,7 @@ func sqlite(tb testing.TB) *bun.DB {
require.Equal(tb, "DB<dialect=sqlite>", db.String())

if _, ok := os.LookupEnv("DEBUG"); ok {
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
}

return db
Expand Down

0 comments on commit b2f8b91

Please sign in to comment.