Skip to content
New issue

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

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

Already on GitHub? # to your account

Support for MS SQL Server #118

Merged
merged 18 commits into from
Jun 3, 2019
Merged
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ coverage:
default:
target: 70%
patch: off
ignore:
- "drivers/bq"
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test:
usql my://root:mypass@localhost:33306/testdb -f testdata/my.sql
usql my://root:mypass@localhost:33308/testdb -f testdata/my.sql
sqlite3 $(PWD)/testdata/testdb.sqlite3 < testdata/sqlite.sql
usql ms://SA:MSSQLServer-Passw0rd@localhost:11433/master -c "IF NOT EXISTS (SELECT * FROM sys.databases WHERE NAME = 'testdb') CREATE DATABASE testdb;"
usql ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb -f testdata/mssql.sql
go test ./... -v -coverprofile=coverage.txt -covermode=count
make testdoc

Expand All @@ -30,6 +32,7 @@ doc: build
./tbls doc my://root:mypass@localhost:33306/testdb -c testdata/test_tbls.yml -f sample/mysql
./tbls doc my://root:mypass@localhost:33308/testdb -c testdata/test_tbls.yml -f sample/mysql8
./tbls doc sq://$(PWD)/testdata/testdb.sqlite3 -c testdata/test_tbls.yml -f sample/sqlite
./tbls doc ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb -c testdata/test_tbls.yml -f sample/mssql
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -c testdata/test_tbls.yml -j -f sample/adjust
./tbls doc my://root:mypass@localhost:33306/testdb -c testdata/test_tbls.yml -t svg -f sample/svg
./tbls doc my://root:mypass@localhost:33306/testdb -c testdata/exclude_test_tbls.yml -f sample/exclude
Expand All @@ -39,6 +42,7 @@ testdoc:
./tbls diff my://root:mypass@localhost:33306/testdb -c testdata/test_tbls.yml sample/mysql
./tbls diff my://root:mypass@localhost:33308/testdb -c testdata/test_tbls.yml sample/mysql8
./tbls diff sq://$(PWD)/testdata/testdb.sqlite3 -c testdata/test_tbls.yml sample/sqlite
./tbls diff ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb -c testdata/test_tbls.yml sample/mssql
./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -c testdata/test_tbls.yml -j sample/adjust
./tbls diff my://root:mypass@localhost:33306/testdb -c testdata/test_tbls.yml -t svg sample/svg
./tbls diff my://root:mypass@localhost:33306/testdb -c testdata/exclude_test_tbls.yml sample/exclude
Expand Down
4 changes: 4 additions & 0 deletions datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"cloud.google.com/go/bigquery"
"github.com/k1LoW/tbls/drivers"
"github.com/k1LoW/tbls/drivers/bq"
"github.com/k1LoW/tbls/drivers/mssql"
"github.com/k1LoW/tbls/drivers/mysql"
"github.com/k1LoW/tbls/drivers/postgres"
"github.com/k1LoW/tbls/drivers/redshift"
Expand Down Expand Up @@ -63,6 +64,9 @@ func Analyze(urlstr string) (*schema.Schema, error) {
case "sqlite3":
s.Name = splitted[len(splitted)-1]
driver = sqlite.NewSqlite(db)
case "mssql":
s.Name = splitted[1]
driver = mssql.NewMssql(db)
default:
return s, errors.WithStack(fmt.Errorf("unsupported driver '%s'", u.Driver))
}
Expand Down
2 changes: 2 additions & 0 deletions datasource/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"testing"

_ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
Expand All @@ -18,6 +19,7 @@ var tests = []struct {
{"my://root:mypass@localhost:33306/testdb", "testdb", 8, 6},
{"pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable", "testdb", 9, 7},
{"json://../testdata/testdb.json", "testdb", 7, 9},
{"ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb", "testdb", 8, 6},
}

func TestMain(m *testing.M) {
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ services:
environment:
- MYSQL_DATABASE=testdb
- MYSQL_ROOT_PASSWORD=mypass
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
restart: always
ports:
- "11433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=MSSQLServer-Passw0rd
Loading