Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to skip version detection #56

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions sqlx-runner/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions sqlx-runner/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ package runner
import (
"testing"

"gopkg.in/mgutz/dat.v1"
"gopkg.in/stretchr/testify.v1/assert"
)

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
}
2 changes: 1 addition & 1 deletion struct_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package dat

import (
"fmt"
"reflect"
"github.com/mgutz/str"
"reflect"

"gopkg.in/mgutz/dat.v1/reflectx"
)
Expand Down