diff --git a/HISTORY.md b/HISTORY.md index 11be80d9..9a7250ac 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +## v2.0.2 + +* Changed references to "github.com/doug-martin/goqu" to "gopkg.in/doug-martin/goqu.v2" + ## v2.0.1 * Fixed issue when `ScanStruct(s)` was used with `SelectDistinct` and caused a panic. diff --git a/README.md b/README.md index 1b5bcdec..ea08e006 100644 --- a/README.md +++ b/README.md @@ -64,17 +64,17 @@ go get -u gopkg.in/doug-martin/goqu.v2 In order to start using goqu with your database you need to load an adapter. We have included some adapters by default. -1. Postgres - `import "github.com/doug-martin/goqu/adapters/postgres"` -2. MySQL - `import "github.com/doug-martin/goqu/adapters/mysql"` -3. SQLite3 - `import "github.com/doug-martin/goqu/adapters/sqlite3"` +1. Postgres - `import "gopkg.in/doug-martin/goqu.v2/adapters/postgres"` +2. MySQL - `import "gopkg.in/doug-martin/goqu.v2/adapters/mysql"` +3. SQLite3 - `import "gopkg.in/doug-martin/goqu.v2/adapters/sqlite3"` Adapters in goqu work the same way as a driver with the database in that they register themselves with goqu once loaded. ```go import ( "database/sql" - "github.com/doug-martin/goqu" - _ "github.com/doug-martin/goqu/adapters/postgres" + "gopkg.in/doug-martin/goqu.v2" + _ "gopkg.in/doug-martin/goqu.v2/postgres" _ "github.com/lib/pq" ) ``` @@ -710,7 +710,7 @@ For example the code for the postgres adapter is fairly short. package postgres import ( - "github.com/doug-martin/goqu" + "gopkg.in/doug-martin/goqu.v2" ) //postgres requires a $ placeholder for prepared statements diff --git a/adapters/mysql/dataset_adapter_test.go b/adapters/mysql/dataset_adapter_test.go index c56fd61d..4089691d 100644 --- a/adapters/mysql/dataset_adapter_test.go +++ b/adapters/mysql/dataset_adapter_test.go @@ -4,9 +4,9 @@ import ( "regexp" "testing" - "github.com/doug-martin/goqu" "github.com/stretchr/testify/suite" "github.com/technotronicoz/testify/assert" + "gopkg.in/doug-martin/goqu.v2" ) type datasetAdapterTest struct { diff --git a/adapters/mysql/mysql.go b/adapters/mysql/mysql.go index 9c4c9c4d..05f28da7 100644 --- a/adapters/mysql/mysql.go +++ b/adapters/mysql/mysql.go @@ -1,105 +1,104 @@ package mysql import ( - "github.com/doug-martin/goqu" + "gopkg.in/doug-martin/goqu.v2" ) var ( - placeholder_rune = '?' - quote_rune = '`' - singlq_quote = '\'' - default_values_frag = []byte("") - mysql_true = []byte("1") - mysql_false = []byte("0") - time_format = "2006-01-02 15:04:05" - operator_lookup = map[goqu.BooleanOperation][]byte{ - goqu.EQ_OP: []byte("="), - goqu.NEQ_OP: []byte("!="), - goqu.GT_OP: []byte(">"), - goqu.GTE_OP: []byte(">="), - goqu.LT_OP: []byte("<"), - goqu.LTE_OP: []byte("<="), - goqu.IN_OP: []byte("IN"), - goqu.NOT_IN_OP: []byte("NOT IN"), - goqu.IS_OP: []byte("IS"), - goqu.IS_NOT_OP: []byte("IS NOT"), - goqu.LIKE_OP: []byte("LIKE BINARY"), - goqu.NOT_LIKE_OP: []byte("NOT LIKE BINARY"), - goqu.I_LIKE_OP: []byte("LIKE"), - goqu.NOT_I_LIKE_OP: []byte("NOT LIKE"), - goqu.REGEXP_LIKE_OP: []byte("REGEXP BINARY"), - goqu.REGEXP_NOT_LIKE_OP: []byte("NOT REGEXP BINARY"), - goqu.REGEXP_I_LIKE_OP: []byte("REGEXP"), - goqu.REGEXP_NOT_I_LIKE_OP: []byte("NOT REGEXP"), - } + placeholder_rune = '?' + quote_rune = '`' + singlq_quote = '\'' + default_values_frag = []byte("") + mysql_true = []byte("1") + mysql_false = []byte("0") + time_format = "2006-01-02 15:04:05" + operator_lookup = map[goqu.BooleanOperation][]byte{ + goqu.EQ_OP: []byte("="), + goqu.NEQ_OP: []byte("!="), + goqu.GT_OP: []byte(">"), + goqu.GTE_OP: []byte(">="), + goqu.LT_OP: []byte("<"), + goqu.LTE_OP: []byte("<="), + goqu.IN_OP: []byte("IN"), + goqu.NOT_IN_OP: []byte("NOT IN"), + goqu.IS_OP: []byte("IS"), + goqu.IS_NOT_OP: []byte("IS NOT"), + goqu.LIKE_OP: []byte("LIKE BINARY"), + goqu.NOT_LIKE_OP: []byte("NOT LIKE BINARY"), + goqu.I_LIKE_OP: []byte("LIKE"), + goqu.NOT_I_LIKE_OP: []byte("NOT LIKE"), + goqu.REGEXP_LIKE_OP: []byte("REGEXP BINARY"), + goqu.REGEXP_NOT_LIKE_OP: []byte("NOT REGEXP BINARY"), + goqu.REGEXP_I_LIKE_OP: []byte("REGEXP"), + goqu.REGEXP_NOT_I_LIKE_OP: []byte("NOT REGEXP"), + } ) type DatasetAdapter struct { - *goqu.DefaultAdapter + *goqu.DefaultAdapter } func (me *DatasetAdapter) SupportsReturn() bool { - return false + return false } func (me *DatasetAdapter) SupportsLimitOnDelete() bool { - return true + return true } func (me *DatasetAdapter) SupportsLimitOnUpdate() bool { - return true + return true } func (me *DatasetAdapter) SupportsOrderByOnDelete() bool { - return true + return true } func (me *DatasetAdapter) SupportsOrderByOnUpdate() bool { - return true + return true } func (me *DatasetAdapter) LiteralString(buf *goqu.SqlBuilder, s string) error { - if buf.IsPrepared { - return me.PlaceHolderSql(buf, s) - } - buf.WriteRune(singlq_quote) - for _, char := range s { - if char == '\'' { // single quote: ' -> \' - buf.WriteString("\\'") - } else if char == '"' { // double quote: " -> \" - buf.WriteString("\\\"") - } else if char == '\\' { // slash: \ -> "\\" - buf.WriteString("\\\\") - } else if char == '\n' { // control: newline: \n -> "\n" - buf.WriteString("\\n") - } else if char == '\r' { // control: return: \r -> "\r" - buf.WriteString("\\r") - } else if char == 0 { // control: NUL: 0 -> "\x00" - buf.WriteString("\\x00") - } else if char == 0x1a { // control: \x1a -> "\x1a" - buf.WriteString("\\x1a") - } else { - buf.WriteRune(char) - } - } - buf.WriteRune(singlq_quote) - return nil + if buf.IsPrepared { + return me.PlaceHolderSql(buf, s) + } + buf.WriteRune(singlq_quote) + for _, char := range s { + if char == '\'' { // single quote: ' -> \' + buf.WriteString("\\'") + } else if char == '"' { // double quote: " -> \" + buf.WriteString("\\\"") + } else if char == '\\' { // slash: \ -> "\\" + buf.WriteString("\\\\") + } else if char == '\n' { // control: newline: \n -> "\n" + buf.WriteString("\\n") + } else if char == '\r' { // control: return: \r -> "\r" + buf.WriteString("\\r") + } else if char == 0 { // control: NUL: 0 -> "\x00" + buf.WriteString("\\x00") + } else if char == 0x1a { // control: \x1a -> "\x1a" + buf.WriteString("\\x1a") + } else { + buf.WriteRune(char) + } + } + buf.WriteRune(singlq_quote) + return nil } func newDatasetAdapter(ds *goqu.Dataset) goqu.Adapter { - def := goqu.NewDefaultAdapter(ds).(*goqu.DefaultAdapter) - def.PlaceHolderRune = placeholder_rune - def.IncludePlaceholderNum = false - def.QuoteRune = quote_rune - def.DefaultValuesFragment = default_values_frag - def.True = mysql_true - def.False = mysql_false - def.TimeFormat = time_format - def.BooleanOperatorLookup = operator_lookup - return &DatasetAdapter{def} + def := goqu.NewDefaultAdapter(ds).(*goqu.DefaultAdapter) + def.PlaceHolderRune = placeholder_rune + def.IncludePlaceholderNum = false + def.QuoteRune = quote_rune + def.DefaultValuesFragment = default_values_frag + def.True = mysql_true + def.False = mysql_false + def.TimeFormat = time_format + def.BooleanOperatorLookup = operator_lookup + return &DatasetAdapter{def} } - func init() { goqu.RegisterAdapter("mysql", newDatasetAdapter) } diff --git a/adapters/mysql/mysql_test.go b/adapters/mysql/mysql_test.go index 5e4c3b0b..b3b74afe 100644 --- a/adapters/mysql/mysql_test.go +++ b/adapters/mysql/mysql_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/doug-martin/goqu" _ "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/suite" "github.com/technotronicoz/testify/assert" + "gopkg.in/doug-martin/goqu.v2" ) const ( diff --git a/adapters/postgres/dataset_adapter_test.go b/adapters/postgres/dataset_adapter_test.go index c5849ca5..25494a9e 100644 --- a/adapters/postgres/dataset_adapter_test.go +++ b/adapters/postgres/dataset_adapter_test.go @@ -3,9 +3,9 @@ package postgres import ( "testing" - "github.com/doug-martin/goqu" "github.com/stretchr/testify/suite" "github.com/technotronicoz/testify/assert" + "gopkg.in/doug-martin/goqu.v2" ) type datasetAdapterTest struct { diff --git a/adapters/postgres/postgres.go b/adapters/postgres/postgres.go index aef2bbb2..e30b88b8 100644 --- a/adapters/postgres/postgres.go +++ b/adapters/postgres/postgres.go @@ -1,7 +1,7 @@ package postgres import ( - "github.com/doug-martin/goqu" + "gopkg.in/doug-martin/goqu.v2" ) const placeholder_rune = '$' diff --git a/adapters/postgres/postgres_test.go b/adapters/postgres/postgres_test.go index 0b61eaa4..5abce484 100644 --- a/adapters/postgres/postgres_test.go +++ b/adapters/postgres/postgres_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/doug-martin/goqu" "github.com/lib/pq" "github.com/stretchr/testify/suite" "github.com/technotronicoz/testify/assert" + "gopkg.in/doug-martin/goqu.v2" ) const schema = ` diff --git a/adapters/sqlite3/dataset_adapter_test.go b/adapters/sqlite3/dataset_adapter_test.go index ab8da7cd..394db1a1 100644 --- a/adapters/sqlite3/dataset_adapter_test.go +++ b/adapters/sqlite3/dataset_adapter_test.go @@ -4,9 +4,9 @@ import ( "regexp" "testing" - "github.com/doug-martin/goqu" "github.com/stretchr/testify/suite" "github.com/technotronicoz/testify/assert" + "gopkg.in/doug-martin/goqu.v2" ) type datasetAdapterTest struct { diff --git a/adapters/sqlite3/sqlite3.go b/adapters/sqlite3/sqlite3.go index a272dfbe..6b7d5ee6 100644 --- a/adapters/sqlite3/sqlite3.go +++ b/adapters/sqlite3/sqlite3.go @@ -1,7 +1,7 @@ package sqlite3 import ( - "github.com/doug-martin/goqu" + "gopkg.in/doug-martin/goqu.v2" ) var ( diff --git a/adapters/sqlite3/sqlite3_test.go b/adapters/sqlite3/sqlite3_test.go index 4b75fd49..438c0017 100644 --- a/adapters/sqlite3/sqlite3_test.go +++ b/adapters/sqlite3/sqlite3_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" - "github.com/doug-martin/goqu" _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/suite" "github.com/technotronicoz/testify/assert" + "gopkg.in/doug-martin/goqu.v2" ) const ( diff --git a/database.go b/database.go index 3085b816..2190caa3 100644 --- a/database.go +++ b/database.go @@ -32,8 +32,8 @@ type ( // import ( // "database/sql" // "fmt" -// "github.com/doug-martin/goqu" -// _ "github.com/doug-martin/goqu/adapters/postgres" +// "gopkg.in/doug-martin/goqu.v2" +// _ "gopkg.in/doug-martin/goqu.v2/adapters/postgres" // _ "github.com/lib/pq" // ) // diff --git a/example_test.go b/example_test.go index 8d266d40..4aacb629 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( "regexp" "github.com/DATA-DOG/go-sqlmock" - "github.com/doug-martin/goqu" + "gopkg.in/doug-martin/goqu.v2" ) var driver *sql.DB