diff --git a/README.md b/README.md index 82b3a3a..366ec9b 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,9 @@ func init() { // Should be disabled in production/release builds. dat.Strict = false + // set this to disable automatic version detection + dat.SkipVersionDetection = false + // Log any query over 10ms as warnings. (optional) runner.LogQueriesThreshold = 10 * time.Millisecond diff --git a/init.go b/init.go index 27b5986..29c08fa 100644 --- a/init.go +++ b/init.go @@ -15,6 +15,9 @@ var Strict = false // EnableInterpolation enables or disable interpolation var EnableInterpolation = false +// SkipVersionDetection prevents automatic version detection +var SkipVersionDetection = false + // maxLookup is the max lookup index for predefined lookup tables const maxLookup = 100 diff --git a/sqlx-runner/db.go b/sqlx-runner/db.go index 03fffbc..d0ecbbf 100644 --- a/sqlx-runner/db.go +++ b/sqlx-runner/db.go @@ -44,6 +44,10 @@ func pgMustNotAllowEscapeSequence(conn *DB) { } func pgSetVersion(db *DB) { + if dat.SkipVersionDetection { + return + } + err := db. SQL("SHOW server_version_num"). QueryScalar(&db.Version) diff --git a/sqlx-runner/db_test.go b/sqlx-runner/db_test.go index d8b62eb..325f85b 100644 --- a/sqlx-runner/db_test.go +++ b/sqlx-runner/db_test.go @@ -3,6 +3,7 @@ package runner import ( "testing" + "gopkg.in/mgutz/dat.v1" "gopkg.in/stretchr/testify.v1/assert" ) @@ -10,3 +11,10 @@ func TestVersion(t *testing.T) { // require at least 9.3+ for testing assert.True(t, testDB.Version > 90300) } + +func TestSkipVersionLookup(t *testing.T) { + dat.SkipVersionDetection = true + versionTestDB := NewDB(sqlDB, "postgres") + assert.True(t, versionTestDB.Version == 0) + dat.SkipVersionDetection = false +} diff --git a/struct_mapping.go b/struct_mapping.go index 5ff659b..e03c69a 100644 --- a/struct_mapping.go +++ b/struct_mapping.go @@ -2,8 +2,8 @@ package dat import ( "fmt" - "reflect" "github.com/mgutz/str" + "reflect" "gopkg.in/mgutz/dat.v1/reflectx" )