remove DebugHook
This commit is contained in:
parent
da752803a5
commit
fb1b65d8a4
|
@ -1,34 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DebugHook struct {
|
|
||||||
Entry *logrus.Entry
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ pg.QueryHook = (*DebugHook)(nil)
|
|
||||||
|
|
||||||
func (logger DebugHook) BeforeQuery(ctx context.Context, evt *pg.QueryEvent) (context.Context, error) {
|
|
||||||
q, err := evt.FormattedQuery()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if evt.Err != nil {
|
|
||||||
logger.Entry.Errorf("%s executing a query:\n%s\n", evt.Err, q)
|
|
||||||
} else {
|
|
||||||
logger.Entry.Info(strings.TrimSpace(string(q)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (DebugHook) AfterQuery(context.Context, *pg.QueryEvent) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
4
main.go
4
main.go
|
@ -55,9 +55,9 @@ func main() {
|
||||||
LogQueries: envutils.GetenvBool("LOG_DB_QUERIES"),
|
LogQueries: envutils.GetenvBool("LOG_DB_QUERIES"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(errors.Wrap(err, "Error establishing a database connection"))
|
logrus.Fatal(errors.Wrap(err, "Couldn't connect to the db"))
|
||||||
}
|
}
|
||||||
logrus.Info("Database connection established")
|
logrus.Info("Connection with the database has been established")
|
||||||
|
|
||||||
//repositories
|
//repositories
|
||||||
userRepository, err := userrepository.NewPGRepository(&userrepository.PGRepositoryConfig{
|
userRepository, err := userrepository.NewPGRepository(&userrepository.PGRepositoryConfig{
|
||||||
|
|
Reference in New Issue
Block a user