Add support for automatic query logging.
This commit is contained in:
parent
5d742837f1
commit
0d3ec872d6
22 changed files with 152 additions and 13 deletions
|
|
@ -1,9 +1,13 @@
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"flag"
|
||||
jetmysql "github.com/go-jet/jet/mysql"
|
||||
"github.com/go-jet/jet/postgres"
|
||||
"github.com/go-jet/jet/tests/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
|
@ -44,3 +48,21 @@ func TestMain(m *testing.M) {
|
|||
|
||||
os.Exit(ret)
|
||||
}
|
||||
|
||||
var loggedSQL string
|
||||
var loggedSQLArgs []interface{}
|
||||
var loggedDebugSQL string
|
||||
|
||||
func init() {
|
||||
jetmysql.SetLogger(func(ctx context.Context, statement jetmysql.LoggableStatement) {
|
||||
loggedSQL, loggedSQLArgs = statement.Sql()
|
||||
loggedDebugSQL = statement.DebugSql()
|
||||
})
|
||||
}
|
||||
|
||||
func requireLogged(t *testing.T, statement postgres.Statement) {
|
||||
query, args := statement.Sql()
|
||||
require.Equal(t, loggedSQL, query)
|
||||
require.Equal(t, loggedSQLArgs, args)
|
||||
require.Equal(t, loggedDebugSQL, statement.DebugSql())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue