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 support for sqlserver dialect, #197 #205

Merged
merged 16 commits into from
Mar 16, 2020
Merged
7 changes: 6 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ on:
pull_request: # Specify a second event with pattern matching
jobs:
test:
name: Test go - ${{ matrix.go_version }} mysql - ${{ matrix.db_versions.mysql_version}} postgres - ${{ matrix.db_versions.postgres_version}}
name: Test go - ${{ matrix.go_version }} mysql - ${{ matrix.db_versions.mysql_version}} postgres - ${{ matrix.db_versions.postgres_version}} sqlserver- ${{ matrix.db_versions.sqlserver_version}}
runs-on: ubuntu-latest
strategy:
matrix:
go_version: ["1.10", "1.11", "latest"]
db_versions:
- mysql_version: 5
postgres_version: 9.6
sqlserver_version: "2017-CU8-ubuntu"
- mysql_version: 5
postgres_version: "10.10"
sqlserver_version: "2017-CU8-ubuntu"
- mysql_version: 8
postgres_version: 11.5
sqlserver_version: "2017-CU8-ubuntu"
steps:
- name: checkout
uses: actions/checkout@v1
Expand All @@ -27,6 +30,7 @@ jobs:
GO_VERSION: ${{ matrix.go_version }}
MYSQL_VERSION: ${{ matrix.db_versions.mysql_version }}
POSTGRES_VERSION: ${{ matrix.db_versions.postgres_version }}
SQLSERVER_VERSION: ${{ matrix.db.versions.sqlserver_version }}
run: docker-compose run goqu-coverage
- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -n $GO_VERSION -e GO_VERSION,MYSQL_VERSION,POSTGRES_VERSION,GITHUB_WORKFLOW,GITHUB_ACTION
Expand All @@ -35,3 +39,4 @@ jobs:
GO_VERSION: ${{ matrix.go_version }}
MYSQL_VERSION: ${{ matrix.db_versions.mysql_version }}
POSTGRES_VERSION: ${{ matrix.db_versions.postgres_version }}
SQLSERVER_VERSION: ${{ matrix.db.versions.sqlserver_version }}
2 changes: 1 addition & 1 deletion dialect/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func DialectOptions() *goqu.SQLDialectOptions {

opts.UseFromClauseForMultipleUpdateTables = false

opts.PlaceHolderRune = '?'
opts.PlaceHolderFragment = []byte("?")
opts.IncludePlaceholderNum = false
opts.QuoteRune = '`'
opts.DefaultValuesFragment = []byte("")
Expand Down
2 changes: 1 addition & 1 deletion dialect/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

func DialectOptions() *goqu.SQLDialectOptions {
do := goqu.DefaultDialectOptions()
do.PlaceHolderRune = '$'
do.PlaceHolderFragment = []byte("$")
do.IncludePlaceholderNum = true
return do
}
Expand Down
2 changes: 1 addition & 1 deletion dialect/sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func DialectOptions() *goqu.SQLDialectOptions {
opts.SupportsWindowFunction = false
opts.SupportsLateral = false

opts.PlaceHolderRune = '?'
opts.PlaceHolderFragment = []byte("?")
opts.IncludePlaceholderNum = false
opts.QuoteRune = '`'
opts.DefaultValuesFragment = []byte("")
Expand Down
90 changes: 90 additions & 0 deletions dialect/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package sqlserver
vlanse marked this conversation as resolved.
Show resolved Hide resolved

import (
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
"github.com/doug-martin/goqu/v9/sqlgen"
)

func DialectOptions() *goqu.SQLDialectOptions {
opts := goqu.DefaultDialectOptions()

opts.UseLiteralIsBools = false

opts.SupportsReturn = false
opts.SupportsOrderByOnUpdate = false
opts.SupportsLimitOnUpdate = false
opts.SupportsLimitOnDelete = false
opts.SupportsOrderByOnDelete = true
opts.SupportsConflictUpdateWhere = false
opts.SupportsInsertIgnoreSyntax = false
opts.SupportsConflictTarget = false
opts.SupportsWithCTE = false
opts.SupportsWithCTERecursive = false
opts.SupportsDistinctOn = false
opts.SupportsWindowFunction = false

opts.PlaceHolderFragment = []byte("@p")
opts.LimitFragment = []byte(" TOP ")
opts.IncludePlaceholderNum = true
opts.DefaultValuesFragment = []byte("")
opts.True = []byte("1")
opts.False = []byte("0")
opts.TimeFormat = "2006-01-02 15:04:05"
opts.BooleanOperatorLookup = map[exp.BooleanOperation][]byte{
exp.EqOp: []byte("="),
exp.NeqOp: []byte("!="),
exp.GtOp: []byte(">"),
exp.GteOp: []byte(">="),
exp.LtOp: []byte("<"),
exp.LteOp: []byte("<="),
exp.InOp: []byte("IN"),
exp.NotInOp: []byte("NOT IN"),
exp.IsOp: []byte("="),
exp.IsNotOp: []byte("IS NOT"),
exp.LikeOp: []byte("LIKE"),
exp.NotLikeOp: []byte("NOT LIKE"),
exp.ILikeOp: []byte("LIKE"),
exp.NotILikeOp: []byte("NOT LIKE"),
exp.RegexpLikeOp: []byte("REGEXP BINARY"),
exp.RegexpNotLikeOp: []byte("NOT REGEXP BINARY"),
exp.RegexpILikeOp: []byte("REGEXP"),
exp.RegexpNotILikeOp: []byte("NOT REGEXP"),
}

opts.FetchFragment = []byte(" FETCH FIRST ")

opts.SelectSQLOrder = []sqlgen.SQLFragmentType{
sqlgen.CommonTableSQLFragment,
sqlgen.SelectWithLimitSQLFragment,
sqlgen.FromSQLFragment,
sqlgen.JoinSQLFragment,
sqlgen.WhereSQLFragment,
sqlgen.GroupBySQLFragment,
sqlgen.HavingSQLFragment,
sqlgen.WindowSQLFragment,
sqlgen.CompoundsSQLFragment,
sqlgen.OrderWithOffsetFetchSQLFragment,
sqlgen.ForSQLFragment,
}

opts.EscapedRunes = map[rune][]byte{
'\'': []byte("\\'"),
'"': []byte("\\\""),
'\\': []byte("\\\\"),
'\n': []byte("\\n"),
'\r': []byte("\\r"),
0: []byte("\\x00"),
0x1a: []byte("\\x1a"),
}

opts.ConflictFragment = []byte("")
opts.ConflictDoUpdateFragment = []byte("")
opts.ConflictDoNothingFragment = []byte("")

return opts
}

func init() {
goqu.RegisterDialect("sqlserver", DialectOptions())
}
Loading