Skip to content

Commit

Permalink
Minor improvements (#236)
Browse files Browse the repository at this point in the history
* use sql instead of sqlx when possible.
* disable metalinter download for now.
* harmonize the way dialects are registered.
  • Loading branch information
stanislas-m committed Sep 2, 2018
1 parent 5a282e9 commit 6cf13d5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ install:
- go get -t -v ./...

before_script:
- go get -u github.com/alecthomas/gometalinter
- gometalinter --install
# - go get -u github.com/alecthomas/gometalinter
# - gometalinter --install
- go build -v -tags sqlite -o tsoda ./soda
- ./tsoda create -e $SODA_DIALECT
- ./tsoda migrate -e $SODA_DIALECT

script:
# - gometalinter --vendor --deadline=5m ./...
- go test -tags sqlite ./... -v
- go test -tags sqlite ./... -v -race

global_env:
- MYSQL_USER="travis"
Expand Down
9 changes: 7 additions & 2 deletions dialect_cockroach.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pop

import (
"database/sql"
"fmt"
"io"
"os"
Expand All @@ -21,6 +22,10 @@ import (
"github.com/pkg/errors"
)

func init() {
AvailableDialects = append(AvailableDialects, "cockroach")
}

var _ dialect = &cockroach{}

type cockroach struct {
Expand Down Expand Up @@ -84,7 +89,7 @@ func (p *cockroach) SelectMany(s store, models *Model, query Query) error {
func (p *cockroach) CreateDB() error {
// createdb -h db -p 5432 -U cockroach enterprise_development
deets := p.ConnectionDetails
db, err := sqlx.Open(deets.Dialect, p.urlWithoutDb())
db, err := sql.Open(deets.Dialect, p.urlWithoutDb())
if err != nil {
return errors.Wrapf(err, "error creating Cockroach database %s", deets.Database)
}
Expand All @@ -103,7 +108,7 @@ func (p *cockroach) CreateDB() error {

func (p *cockroach) DropDB() error {
deets := p.ConnectionDetails
db, err := sqlx.Open(deets.Dialect, p.urlWithoutDb())
db, err := sql.Open(deets.Dialect, p.urlWithoutDb())
if err != nil {
return errors.Wrapf(err, "error dropping Cockroach database %s", deets.Database)
}
Expand Down
10 changes: 7 additions & 3 deletions dialect_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pop

import (
"bytes"
"database/sql"
"fmt"
"io"
"os"
Expand All @@ -14,11 +15,14 @@ import (
"github.com/gobuffalo/fizz/translators"
"github.com/gobuffalo/pop/columns"
"github.com/gobuffalo/pop/logging"
"github.com/jmoiron/sqlx"
"github.com/markbates/going/defaults"
"github.com/pkg/errors"
)

func init() {
AvailableDialects = append(AvailableDialects, "mysql")
}

var _ dialect = &mysql{}

type mysql struct {
Expand Down Expand Up @@ -82,7 +86,7 @@ func (m *mysql) SelectMany(s store, models *Model, query Query) error {
// CreateDB creates a new database, from the given connection credentials
func (m *mysql) CreateDB() error {
deets := m.ConnectionDetails
db, err := sqlx.Open(deets.Dialect, m.urlWithoutDb())
db, err := sql.Open(deets.Dialect, m.urlWithoutDb())
if err != nil {
return errors.Wrapf(err, "error creating MySQL database %s", deets.Database)
}
Expand All @@ -103,7 +107,7 @@ func (m *mysql) CreateDB() error {
// DropDB drops an existing database, from the given connection credentials
func (m *mysql) DropDB() error {
deets := m.ConnectionDetails
db, err := sqlx.Open(deets.Dialect, m.urlWithoutDb())
db, err := sql.Open(deets.Dialect, m.urlWithoutDb())
if err != nil {
return errors.Wrapf(err, "error dropping MySQL database %s", deets.Database)
}
Expand Down
9 changes: 7 additions & 2 deletions dialect_postgresql.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pop

import (
"database/sql"
"fmt"
"io"
"os"
Expand All @@ -18,6 +19,10 @@ import (
"github.com/pkg/errors"
)

func init() {
AvailableDialects = append(AvailableDialects, "postgres")
}

var _ dialect = &postgresql{}

type postgresql struct {
Expand Down Expand Up @@ -81,7 +86,7 @@ func (p *postgresql) SelectMany(s store, models *Model, query Query) error {
func (p *postgresql) CreateDB() error {
// createdb -h db -p 5432 -U postgres enterprise_development
deets := p.ConnectionDetails
db, err := sqlx.Open(deets.Dialect, p.urlWithoutDb())
db, err := sql.Open(deets.Dialect, p.urlWithoutDb())
if err != nil {
return errors.Wrapf(err, "error creating PostgreSQL database %s", deets.Database)
}
Expand All @@ -100,7 +105,7 @@ func (p *postgresql) CreateDB() error {

func (p *postgresql) DropDB() error {
deets := p.ConnectionDetails
db, err := sqlx.Open(deets.Dialect, p.urlWithoutDb())
db, err := sql.Open(deets.Dialect, p.urlWithoutDb())
if err != nil {
return errors.Wrapf(err, "error dropping PostgreSQL database %s", deets.Database)
}
Expand Down
2 changes: 1 addition & 1 deletion pop.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pop

// AvailableDialects lists the available database dialects
var AvailableDialects = []string{"postgres", "mysql", "cockroach"}
var AvailableDialects = []string{}

// DialectSupported checks support for the given database dialect
func DialectSupported(d string) bool {
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function test {
./tsoda drop -e $SODA_DIALECT -c ./database.yml
./tsoda create -e $SODA_DIALECT -c ./database.yml
./tsoda migrate -e $SODA_DIALECT -c ./database.yml
go test -tags sqlite $verbose $(go list ./... | grep -v /vendor/)
go test -race -tags sqlite $verbose $(go list ./... | grep -v /vendor/)
}

test "postgres"
Expand Down

0 comments on commit 6cf13d5

Please sign in to comment.