Skip to content

Commit

Permalink
v2.0.2
Browse files Browse the repository at this point in the history
* Changed references to "github.com/doug-martin/goqu" to "gopkg.in/doug-martin/goqu.v2"
  • Loading branch information
doug-martin committed May 29, 2015
1 parent 39ce306 commit 604f721
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 87 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
```
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion adapters/mysql/dataset_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
139 changes: 69 additions & 70 deletions adapters/mysql/mysql.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion adapters/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion adapters/postgres/dataset_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion adapters/postgres/postgres.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package postgres

import (
"github.com/doug-martin/goqu"
"gopkg.in/doug-martin/goqu.v2"
)

const placeholder_rune = '$'
Expand Down
2 changes: 1 addition & 1 deletion adapters/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
2 changes: 1 addition & 1 deletion adapters/sqlite3/dataset_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion adapters/sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sqlite3

import (
"github.com/doug-martin/goqu"
"gopkg.in/doug-martin/goqu.v2"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion adapters/sqlite3/sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// )
//
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 604f721

Please sign in to comment.