Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m committed Sep 21, 2019
2 parents aab726f + 3ef63dc commit c464414
Show file tree
Hide file tree
Showing 51 changed files with 1,806 additions and 1,013 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build:
$(GO_BIN) build -v .

test:
packr2
# packr2
$(GO_BIN) test -tags ${TAGS} ./...

ci-test:
Expand Down
100 changes: 19 additions & 81 deletions SHOULDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,126 +5,64 @@ Pop does not try to reinvent the wheel! Instead, it uses the already great wheel
Thank you to the following **GIANTS**:


* [github.com/blang/semver](https://godoc.org/github.com/blang/semver)
* [github.com/cockroachdb/apd](https://godoc.org/github.com/cockroachdb/apd)

* [github.com/cockroachdb/cockroach-go/crdb](https://godoc.org/github.com/cockroachdb/cockroach-go/crdb)
* [github.com/cockroachdb/cockroach-go](https://godoc.org/github.com/cockroachdb/cockroach-go)

* [github.com/fatih/color](https://godoc.org/github.com/fatih/color)

* [github.com/fatih/structs](https://godoc.org/github.com/fatih/structs)

* [github.com/go-sql-driver/mysql](https://godoc.org/github.com/go-sql-driver/mysql)

* [github.com/gobuffalo/attrs](https://godoc.org/github.com/gobuffalo/attrs)

* [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy)

* [github.com/gobuffalo/fizz](https://godoc.org/github.com/gobuffalo/fizz)

* [github.com/gobuffalo/fizz/translators](https://godoc.org/github.com/gobuffalo/fizz/translators)

* [github.com/gobuffalo/flect](https://godoc.org/github.com/gobuffalo/flect)

* [github.com/gobuffalo/flect/name](https://godoc.org/github.com/gobuffalo/flect/name)

* [github.com/gobuffalo/github_flavored_markdown](https://godoc.org/github.com/gobuffalo/github_flavored_markdown)

* [github.com/gobuffalo/github_flavored_markdown/internal/russross/blackfriday](https://godoc.org/github.com/gobuffalo/github_flavored_markdown/internal/russross/blackfriday)
* [github.com/gobuffalo/genny](https://godoc.org/github.com/gobuffalo/genny)

* [github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/highlight_diff](https://godoc.org/github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/highlight_diff)
* [github.com/gobuffalo/gogen](https://godoc.org/github.com/gobuffalo/gogen)

* [github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/highlight_go](https://godoc.org/github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/highlight_go)

* [github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/octicon](https://godoc.org/github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/octicon)

* [github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/sanitized_anchor_name](https://godoc.org/github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/sanitized_anchor_name)

* [github.com/gobuffalo/makr](https://godoc.org/github.com/gobuffalo/makr)
* [github.com/gobuffalo/logger](https://godoc.org/github.com/gobuffalo/logger)

* [github.com/gobuffalo/nulls](https://godoc.org/github.com/gobuffalo/nulls)

* [github.com/gobuffalo/packd](https://godoc.org/github.com/gobuffalo/packd)

* [github.com/gobuffalo/plush](https://godoc.org/github.com/gobuffalo/plush)

* [github.com/gobuffalo/plush/ast](https://godoc.org/github.com/gobuffalo/plush/ast)
* [github.com/gobuffalo/packr/v2](https://godoc.org/github.com/gobuffalo/packr/v2)

* [github.com/gobuffalo/plush/lexer](https://godoc.org/github.com/gobuffalo/plush/lexer)

* [github.com/gobuffalo/plush/parser](https://godoc.org/github.com/gobuffalo/plush/parser)

* [github.com/gobuffalo/plush/token](https://godoc.org/github.com/gobuffalo/plush/token)

* [github.com/gobuffalo/syncx](https://godoc.org/github.com/gobuffalo/syncx)

* [github.com/gobuffalo/tags](https://godoc.org/github.com/gobuffalo/tags)

* [github.com/gobuffalo/tags/form](https://godoc.org/github.com/gobuffalo/tags/form)

* [github.com/gobuffalo/tags/form/bootstrap](https://godoc.org/github.com/gobuffalo/tags/form/bootstrap)

* [github.com/gobuffalo/uuid](https://godoc.org/github.com/gobuffalo/uuid)
* [github.com/gobuffalo/plush](https://godoc.org/github.com/gobuffalo/plush)

* [github.com/gobuffalo/validate](https://godoc.org/github.com/gobuffalo/validate)

* [github.com/gobuffalo/validate/validators](https://godoc.org/github.com/gobuffalo/validate/validators)

* [github.com/gobuffalo/x/defaults](https://godoc.org/github.com/gobuffalo/x/defaults)

* [github.com/gofrs/uuid](https://godoc.org/github.com/gofrs/uuid)

* [github.com/jackc/pgx](https://godoc.org/github.com/jackc/pgx)

* [github.com/jackc/pgx/chunkreader](https://godoc.org/github.com/jackc/pgx/chunkreader)

* [github.com/jackc/pgx/internal/sanitize](https://godoc.org/github.com/jackc/pgx/internal/sanitize)

* [github.com/jackc/pgx/pgio](https://godoc.org/github.com/jackc/pgx/pgio)
* [github.com/jackc/fake](https://godoc.org/github.com/jackc/fake)

* [github.com/jackc/pgx/pgproto3](https://godoc.org/github.com/jackc/pgx/pgproto3)

* [github.com/jackc/pgx/pgtype](https://godoc.org/github.com/jackc/pgx/pgtype)
* [github.com/jackc/pgx](https://godoc.org/github.com/jackc/pgx)

* [github.com/jmoiron/sqlx](https://godoc.org/github.com/jmoiron/sqlx)

* [github.com/jmoiron/sqlx/reflectx](https://godoc.org/github.com/jmoiron/sqlx/reflectx)

* [github.com/joho/godotenv](https://godoc.org/github.com/joho/godotenv)

* [github.com/kballard/go-shellquote](https://godoc.org/github.com/kballard/go-shellquote)

* [github.com/lib/pq](https://godoc.org/github.com/lib/pq)

* [github.com/lib/pq/oid](https://godoc.org/github.com/lib/pq/oid)

* [github.com/markbates/going/defaults](https://godoc.org/github.com/markbates/going/defaults)

* [github.com/markbates/going/randx](https://godoc.org/github.com/markbates/going/randx)
* [github.com/mattn/go-colorable](https://godoc.org/github.com/mattn/go-colorable)

* [github.com/markbates/inflect](https://godoc.org/github.com/markbates/inflect)
* [github.com/mattn/go-isatty](https://godoc.org/github.com/mattn/go-isatty)

* [github.com/markbates/oncer](https://godoc.org/github.com/markbates/oncer)

* [github.com/microcosm-cc/bluemonday](https://godoc.org/github.com/microcosm-cc/bluemonday)
* [github.com/mattn/go-sqlite3](https://godoc.org/github.com/mattn/go-sqlite3)

* [github.com/pkg/errors](https://godoc.org/github.com/pkg/errors)

* [github.com/rogpeppe/go-internal/modfile](https://godoc.org/github.com/rogpeppe/go-internal/modfile)

* [github.com/rogpeppe/go-internal/module](https://godoc.org/github.com/rogpeppe/go-internal/module)

* [github.com/rogpeppe/go-internal/semver](https://godoc.org/github.com/rogpeppe/go-internal/semver)

* [github.com/serenize/snaker](https://godoc.org/github.com/serenize/snaker)

* [github.com/sergi/go-diff/diffmatchpatch](https://godoc.org/github.com/sergi/go-diff/diffmatchpatch)

* [github.com/sourcegraph/annotate](https://godoc.org/github.com/sourcegraph/annotate)
* [github.com/satori/go.uuid](https://godoc.org/github.com/satori/go.uuid)

* [github.com/sourcegraph/syntaxhighlight](https://godoc.org/github.com/sourcegraph/syntaxhighlight)
* [github.com/shopspring/decimal](https://godoc.org/github.com/shopspring/decimal)

* [golang.org/x/net/html](https://godoc.org/golang.org/x/net/html)
* [github.com/spf13/cobra](https://godoc.org/github.com/spf13/cobra)

* [golang.org/x/net/html/atom](https://godoc.org/golang.org/x/net/html/atom)
* [github.com/stretchr/testify](https://godoc.org/github.com/stretchr/testify)

* [golang.org/x/sync/errgroup](https://godoc.org/golang.org/x/sync/errgroup)
* [golang.org/x/sync](https://godoc.org/golang.org/x/sync)

* [gopkg.in/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)
31 changes: 16 additions & 15 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
strategy:
matrix:
# SQLite3
go 1.12 (off) sqlite:
go_version: "1.12"
go 1.13 (off) sqlite:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "sqlite"
steps:
Expand All @@ -23,8 +23,8 @@ jobs:
strategy:
matrix:
# SQLite3
go 1.12 (off) sqlite:
go_version: "1.12"
go 1.13 (off) sqlite:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "sqlite"
steps:
Expand All @@ -36,9 +36,6 @@ jobs:
strategy:
matrix:
# Postgres
go 1.10 postgres:
go_version: "1.10"
SODA_DIALECT: "postgres"
go 1.11 (off) postgres:
go_version: "1.11.5"
GO111MODULE: "off"
Expand All @@ -47,25 +44,29 @@ jobs:
go_version: "1.12"
GO111MODULE: "off"
SODA_DIALECT: "postgres"
go 1.13 (off) postgres:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "postgres"
# Cockroach
go 1.12 (off) cockroach:
go_version: "1.12"
go 1.13 (off) cockroach:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "cockroach"
# Cockroach SSL
go 1.12 (off) cockroach SSL:
go_version: "1.12"
go 1.13 (off) cockroach SSL:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "cockroach_ssl"
# MySQL
go 1.12 (off) mysql:
go_version: "1.12"
go 1.13 (off) mysql:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "mysql"
MYSQL_PORT: "3307"
# SQLite3
go 1.12 (off) sqlite:
go_version: "1.12"
go 1.13 (off) sqlite:
go_version: "1.13"
GO111MODULE: "off"
SODA_DIALECT: "sqlite"
steps:
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func LoadConfigFile() error {
if err != nil {
return err
}
defer f.Close()
return LoadFrom(f)
}

Expand Down
3 changes: 3 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (c *Connection) Open() error {
if details.IdlePool != 0 {
db.SetMaxIdleConns(details.IdlePool)
}
if details.ConnMaxLifetime > 0 {
db.SetConnMaxLifetime(details.ConnMaxLifetime)
}
c.Store = &dB{db}

if d, ok := c.Dialect.(afterOpenable); ok {
Expand Down
4 changes: 3 additions & 1 deletion connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ type ConnectionDetails struct {
Pool int
// Defaults to 2. See https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns
IdlePool int
Options map[string]string
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime
ConnMaxLifetime time.Duration
Options map[string]string
// Query string encoded options from URL. Example: "sslmode=disable"
RawOptions string
}
Expand Down
8 changes: 4 additions & 4 deletions connection_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func Test_ConnectionDetails_Finalize(t *testing.T) {
r := require.New(t)

cd := &ConnectionDetails{
URL: "postgres://user:pass@host:port/database",
URL: "postgres://user:pass@host:1337/database",
}
err := cd.Finalize()
r.NoError(err)
Expand All @@ -19,7 +19,7 @@ func Test_ConnectionDetails_Finalize(t *testing.T) {
r.Equal("postgres", cd.Dialect)
r.Equal("host", cd.Host)
r.Equal("pass", cd.Password)
r.Equal("port", cd.Port)
r.Equal("1337", cd.Port)
r.Equal("user", cd.User)
}

Expand All @@ -46,14 +46,14 @@ func Test_ConnectionDetails_Finalize_Cockroach(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
URL: "postgres://user:pass@host:port/database?sslmode=require&sslrootcert=certs/ca.crt&sslkey=certs/client.key&sslcert=certs/client.crt",
URL: "postgres://user:pass@host:1337/database?sslmode=require&sslrootcert=certs/ca.crt&sslkey=certs/client.key&sslcert=certs/client.crt",
}
err := cd.Finalize()
r.NoError(err)
r.Equal("cockroach", cd.Dialect)
r.Equal("database", cd.Database)
r.Equal("host", cd.Host)
r.Equal("port", cd.Port)
r.Equal("1337", cd.Port)
r.Equal("user", cd.User)
r.Equal("pass", cd.Password)
}
Expand Down
26 changes: 19 additions & 7 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,37 @@ import (
"github.com/gobuffalo/pop/columns"
)

type crudable interface {
SelectOne(store, *Model, Query) error
SelectMany(store, *Model, Query) error
Create(store, *Model, columns.Columns) error
Update(store, *Model, columns.Columns) error
Destroy(store, *Model) error
}

type fizzable interface {
FizzTranslator() fizz.Translator
}

type quotable interface {
Quote(key string) string
}

type dialect interface {
crudable
fizzable
quotable
Name() string
URL() string
MigrationURL() string
Details() *ConnectionDetails
TranslateSQL(string) string
Create(store, *Model, columns.Columns) error
Update(store, *Model, columns.Columns) error
Destroy(store, *Model) error
SelectOne(store, *Model, Query) error
SelectMany(store, *Model, Query) error
CreateDB() error
DropDB() error
DumpSchema(io.Writer) error
LoadSchema(io.Reader) error
FizzTranslator() fizz.Translator
Lock(func() error) error
TruncateAll(*Connection) error
Quote(key string) string
}

type afterOpenable interface {
Expand Down
6 changes: 3 additions & 3 deletions dialect_cockroach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ func Test_Cockroach_URL_Raw(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
URL: "scheme://user:pass@host:port/database?option1=value1",
URL: "scheme://user:pass@host:1337/database?option1=value1",
}
err := cd.Finalize()
r.NoError(err)
m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.Equal("scheme://user:pass@host:port/database?option1=value1", m.URL())
r.Equal("postgres://user:pass@host:port/?option1=value1", m.urlWithoutDb())
r.Equal("scheme://user:pass@host:1337/database?option1=value1", m.URL())
r.Equal("postgres://user:pass@host:1337/?option1=value1", m.urlWithoutDb())
}

func Test_Cockroach_URL_Build(t *testing.T) {
Expand Down
10 changes: 3 additions & 7 deletions dialect_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ func (commonDialect) Quote(key string) string {
return fmt.Sprintf(`"%s"`, key)
}

type quoter interface {
Quote(key string) string
}

func genericCreate(s store, model *Model, cols columns.Columns, quoter quoter) error {
func genericCreate(s store, model *Model, cols columns.Columns, quoter quotable) error {
keyType := model.PrimaryKeyType()
switch keyType {
case "int", "int64":
Expand Down Expand Up @@ -90,7 +86,7 @@ func genericCreate(s store, model *Model, cols columns.Columns, quoter quoter) e
return errors.Errorf("can not use %s as a primary key type!", keyType)
}

func genericUpdate(s store, model *Model, cols columns.Columns, quoter quoter) error {
func genericUpdate(s store, model *Model, cols columns.Columns, quoter quotable) error {
stmt := fmt.Sprintf("UPDATE %s SET %s WHERE %s", quoter.Quote(model.TableName()), cols.Writeable().QuotedUpdateString(quoter), model.whereNamedID())
log(logging.SQL, stmt, model.ID())
_, err := s.NamedExec(stmt, model.Value)
Expand All @@ -100,7 +96,7 @@ func genericUpdate(s store, model *Model, cols columns.Columns, quoter quoter) e
return nil
}

func genericDestroy(s store, model *Model, quoter quoter) error {
func genericDestroy(s store, model *Model, quoter quotable) error {
stmt := fmt.Sprintf("DELETE FROM %s WHERE %s", quoter.Quote(model.TableName()), model.whereID())
_, err := genericExec(s, stmt, model.ID())
if err != nil {
Expand Down

0 comments on commit c464414

Please sign in to comment.