DestName & NormalCols now live in root dbx package utilizing union interfaces. SoftDelete helper has been dropped.
37 lines
818 B
Go
37 lines
818 B
Go
package dbxm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"gitea.auvem.com/go-toolkit/dbx"
|
|
"gitea.auvem.com/go-toolkit/dbx/internal/dbxshared"
|
|
"github.com/fatih/color"
|
|
"github.com/go-jet/jet/v2/mysql"
|
|
)
|
|
|
|
func init() {
|
|
dbxshared.RegisterLogger(dbx.DialectMySQL, &_mysqlLogger{})
|
|
}
|
|
|
|
type _mysqlLogger struct{}
|
|
|
|
func (_mysqlLogger) InitLogger() {
|
|
mysql.SetQueryLogger(func(ctx context.Context, queryInfo mysql.QueryInfo) {
|
|
_, args := queryInfo.Statement.Sql()
|
|
dbxshared.DBModule.Logger().Debug(
|
|
"Executed SQL query",
|
|
"args", args,
|
|
"duration", queryInfo.Duration,
|
|
"rows", queryInfo.RowsProcessed,
|
|
"err", queryInfo.Err,
|
|
)
|
|
|
|
lines := strings.Split(queryInfo.Statement.DebugSql(), "\n")
|
|
for i, line := range lines {
|
|
fmt.Printf("%s\t%s\n", color.CyanString(fmt.Sprintf("%03d", i)), line)
|
|
}
|
|
})
|
|
}
|