Skip to content

Commit

Permalink
Add support for pax driver; require Go 1.9+.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Jun 16, 2018
1 parent 57f09ea commit a225819
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 32 deletions.
9 changes: 9 additions & 0 deletions .github/docker-compose-pgx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
version: '3'
services:
postgres:
image: postgres:${REFORM_IMAGE_VERSION}
environment:
- TZ=Europe/Moscow
ports:
- 127.0.0.1:5432:5432
19 changes: 11 additions & 8 deletions .github/test-dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"os/exec"
"strconv"
"strings"
)

Expand All @@ -20,7 +21,7 @@ type config struct {
var configs = []config{
// https://www.postgresql.org/support/versioning/
{
[]string{"postgres"},
[]string{"postgres", "pgx"},
[]string{
"9.3",
"9.4",
Expand Down Expand Up @@ -84,7 +85,7 @@ func gen() {
}

const filename = ".travis.yml"
const start = "# Generated with 'go run .github/test-dc.go'."
const start = "# Generated with 'go run .github/test-dc.go gen'."
b, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
Expand All @@ -108,12 +109,14 @@ func testOne() {
v := os.Getenv("REFORM_IMAGE_VERSION")
log.Printf("REFORM_TARGET=%s REFORM_IMAGE_VERSION=%s", t, v)

for _, c := range []string{
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform pull", t),
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform up -d --remove-orphans --force-recreate", t),
fmt.Sprintf("make %s", t),
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform down --remove-orphans --volumes", t),
} {
var commands []string
if offline, _ := strconv.ParseBool(os.Getenv("REFORM_OFFLINE")); !offline {
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform pull", t))
}
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform up -d --remove-orphans --force-recreate", t))
commands = append(commands, fmt.Sprintf("make %s", t))
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform down --remove-orphans --volumes", t))
for _, c := range commands {
log.Print(c)
args := strings.Split(c, " ")
cmd := exec.Command(args[0], args[1:]...)
Expand Down
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: required
language: go

go:
- 1.8.x
- 1.9.x
- 1.10.x
- master
Expand Down Expand Up @@ -37,9 +36,9 @@ env:
global:
- GORACE="halt_on_error=1"

# Generated with 'go run .github/test-dc.go'.
# 16 combinations:
# postgres: 9.3, 9.4, 9.5, 9.6, 10
# Generated with 'go run .github/test-dc.go gen'.
# 21 combinations:
# postgres, pgx: 9.3, 9.4, 9.5, 9.6, 10
# mysql, mysql-traditional: 5.5, 5.6, 5.7, 8.0
# sqlite3: dummy
# mssql, sqlserver: latest
Expand All @@ -49,6 +48,11 @@ env:
- REFORM_TARGET=postgres REFORM_IMAGE_VERSION=9.5
- REFORM_TARGET=postgres REFORM_IMAGE_VERSION=9.6
- REFORM_TARGET=postgres REFORM_IMAGE_VERSION=10
- REFORM_TARGET=pgx REFORM_IMAGE_VERSION=9.3
- REFORM_TARGET=pgx REFORM_IMAGE_VERSION=9.4
- REFORM_TARGET=pgx REFORM_IMAGE_VERSION=9.5
- REFORM_TARGET=pgx REFORM_IMAGE_VERSION=9.6
- REFORM_TARGET=pgx REFORM_IMAGE_VERSION=10

- REFORM_TARGET=mysql REFORM_IMAGE_VERSION=5.5
- REFORM_TARGET=mysql REFORM_IMAGE_VERSION=5.6
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.4.0 (not released yet)

* Go 1.9+ is now required.
* Added support for [github.com/jackc/pgx](https://github.com/jackc/pgx) driver.

## v1.3.2 (2018-XX-XX, https://github.com/go-reform/reform/milestones/v1.3.2)

* Go 1.8+ is now required due to changes in github.com/lib/pq driver.
Expand Down
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ REFORM_TEST_FLAGS ?=
# install dependencies
deps:
go get -u github.com/lib/pq
go get -u github.com/jackc/pgx/stdlib
go get -u github.com/go-sql-driver/mysql
go get -u github.com/mattn/go-sqlite3
go get -u github.com/denisenkom/go-mssqldb

go get -u github.com/AlekSi/pointer
go get -u github.com/stretchr/testify/...
go get -u syreclabs.com/go/faker
go get -u gopkg.in/alecthomas/gometalinter.v1
go get -u gopkg.in/alecthomas/gometalinter.v2
go get -u github.com/AlekSi/gocoverutil

gometalinter.v1 --install
gometalinter.v2 --install

# run all linters
check:
-gometalinter.v1 ./... --deadline=180s --severity=vet:error
-gometalinter.v2 ./... --tests --deadline=180s --severity=vet:error

# run unit tests, generate models, install tools
test:
Expand Down Expand Up @@ -58,7 +59,7 @@ test-db:
test-dc:
go run .github/test-dc.go test

# run unit tests and integration tests for PostgreSQL
# run unit tests and integration tests for PostgreSQL (postgres driver)
postgres: export REFORM_DATABASE = postgres
postgres: export REFORM_DRIVER = postgres
postgres: export REFORM_ROOT_SOURCE = postgres://[email protected]/template1?sslmode=disable
Expand All @@ -67,6 +68,15 @@ postgres: export REFORM_TEST_SOURCE = postgres://[email protected]/reform-datab
postgres: test
make test-db

# run unit tests and integration tests for PostgreSQL (pgx driver)
pgx: export REFORM_DATABASE = postgres
pgx: export REFORM_DRIVER = pgx
pgx: export REFORM_ROOT_SOURCE = postgres://[email protected]/template1?sslmode=disable
pgx: export REFORM_INIT_SOURCE = postgres://[email protected]/reform-database?sslmode=disable&TimeZone=UTC
pgx: export REFORM_TEST_SOURCE = postgres://[email protected]/reform-database?sslmode=disable&TimeZone=America/New_York
pgx: test
make test-db

# run unit tests and integration tests for MySQL (ANSI SQL mode)
mysql: export REFORM_DATABASE = mysql
mysql: export REFORM_DRIVER = mysql
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# reform

[![Release](https://github-release-version.herokuapp.com/github/go-reform/reform/release.svg?style=flat)](https://github.com/go-reform/reform/releases/latest)
[![GoDoc](https://godoc.org/gopkg.in/reform.v1?status.svg)](https://godoc.org/gopkg.in/reform.v1)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-reform/reform?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Expand All @@ -16,18 +17,19 @@ as opposed to `interface{}`, type system sidestepping, and runtime reflection. I

Supported SQL dialects:

| RDBMS | Library and drivers | Tested with
| ----- | ------------------- | -----------
| PostgreSQL | [github.com/lib/pq](https://github.com/lib/pq) (`postgres`) | All [supported](https://www.postgresql.org/support/versioning/) versions.
| MySQL | [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) (`mysql`) | All [supported](https://www.mysql.com/support/supportedplatforms/database.html) versions.
| SQLite3 | [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) (`sqlite3`) |
| Microsoft SQL Server | [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) (`mssql`, `sqlserver`) | Windows: SQL2008R2SP2, SQL2012SP1, SQL2014, SQL2016. Linux: [`microsoft/mssql-server-linux:latest` Docker image](https://hub.docker.com/r/microsoft/mssql-server-linux/).
| RDBMS | Library and drivers | Tested with
| ----- | ------------------- | -----------
| PostgreSQL | [github.com/lib/pq](https://github.com/lib/pq) (`postgres`), [github.com/jackc/pgx/stdlib](https://github.com/jackc/pgx) (`pgx`) | All [supported](https://www.postgresql.org/support/versioning/) versions.
| MySQL | [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) (`mysql`) | All [supported](https://www.mysql.com/support/supportedplatforms/database.html) versions.
| SQLite3 | [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) (`sqlite3`) |
| Microsoft SQL Server | [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) (`mssql`, `sqlserver`) | Windows: SQL2008R2SP2, SQL2012SP1, SQL2014, SQL2016. Linux: [`microsoft/mssql-server-linux:latest` Docker image](https://hub.docker.com/r/microsoft/mssql-server-linux/).

Note that for MySQL [`clientFoundRows=true`](https://github.com/go-sql-driver/mysql#clientfoundrows) flag is required.


## Quickstart

1. Make sure you are using Go 1.8+. Install or update `reform` package, `reform` and `reform-db` commands
1. Make sure you are using Go 1.9+. Install or update `reform` package, `reform` and `reform-db` commands
(see about versioning below):

```
Expand Down Expand Up @@ -58,7 +60,7 @@ Note that for MySQL [`clientFoundRows=true`](https://github.com/go-sql-driver/my
Magic comment `//reform:people` links this model to `people` table or view in SQL database.
The first value in field's `reform` tag is a column name. `pk` marks primary key.
Use value `-` or omit tag completely to skip a field.
Use pointers for nullable fields.
Use pointers (recommended) or `sql.NullXXX` types for nullable fields.
4. Run `reform [package or directory]` or `go generate [package or file]`. This will create `person_reform.go`
in the same package with type `PersonTable` and methods on `Person`.
Expand Down
1 change: 1 addition & 0 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

_ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/jackc/pgx/stdlib"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"

Expand Down
14 changes: 9 additions & 5 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ func (s *ReformSuite) TestAbortedTransaction() {
tx, err := DB.Begin()
s.Require().NoError(err)
s.NoError(tx.Insert(person1))
s.EqualError(tx.Insert(person1), `pq: duplicate key value violates unique constraint "people_pkey"`)
s.EqualError(tx.Insert(person2), `pq: current transaction is aborted, commands ignored until end of transaction block`)
s.EqualError(tx.Commit(), `pq: Could not complete operation in a failed transaction`)
s.Contains(tx.Insert(person1).Error(), `duplicate key value violates unique constraint "people_pkey"`)
s.Contains(tx.Insert(person2).Error(), `current transaction is aborted, commands ignored until end of transaction block`)
err = tx.Commit()
s.Require().Error(err)
if err.Error() != `pq: Could not complete operation in a failed transaction` && err.Error() != `commit unexpectedly resulted in rollback` {
s.Failf("unexpected error", "actual: %q", err)
}
s.Equal(tx.Rollback(), reform.ErrTxDone)
s.EqualError(DB.Reload(person1), reform.ErrNoRows.Error())
s.EqualError(DB.Reload(person2), reform.ErrNoRows.Error())
Expand All @@ -117,8 +121,8 @@ func (s *ReformSuite) TestAbortedTransaction() {
tx, err = DB.Begin()
s.Require().NoError(err)
s.NoError(tx.Insert(person1))
s.EqualError(tx.Insert(person1), `pq: duplicate key value violates unique constraint "people_pkey"`)
s.EqualError(tx.Insert(person2), `pq: current transaction is aborted, commands ignored until end of transaction block`)
s.Contains(tx.Insert(person1).Error(), `duplicate key value violates unique constraint "people_pkey"`)
s.Contains(tx.Insert(person2).Error(), `current transaction is aborted, commands ignored until end of transaction block`)
s.NoError(tx.Rollback())
s.Equal(tx.Commit(), reform.ErrTxDone)
s.Equal(tx.Rollback(), reform.ErrTxDone)
Expand Down
2 changes: 1 addition & 1 deletion dialects/dialects.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// ForDriver returns reform Dialect for given driver string, or nil.
func ForDriver(driver string) reform.Dialect {
switch driver {
case "postgres":
case "postgres", "pgx":
return postgresql.Dialect
case "mysql":
return mysql.Dialect
Expand Down
1 change: 1 addition & 0 deletions reform-db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

_ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/jackc/pgx/stdlib"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"

Expand Down
4 changes: 2 additions & 2 deletions reform/version_check.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !go1.8
// +build !go1.9

package main

Expand All @@ -8,5 +8,5 @@ import (
)

func init() {
log.Fatalf("reform requires Go 1.8+, but was compiled with %s.", runtime.Version())
log.Fatalf("reform requires Go 1.9+, but was compiled with %s.", runtime.Version())
}

0 comments on commit a225819

Please sign in to comment.