Skip to content

Commit

Permalink
Merge pull request #134 from go-reform/v1-3
Browse files Browse the repository at this point in the history
Version 1.3.0
  • Loading branch information
AlekSi committed Dec 1, 2017
2 parents b4bf68a + 6174bea commit a76bd30
Show file tree
Hide file tree
Showing 28 changed files with 424 additions and 220 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
@@ -0,0 +1,2 @@
codecov:
branch: v1-stable
23 changes: 12 additions & 11 deletions .drone-local.yml
Expand Up @@ -46,11 +46,12 @@ services:
DATABASE: postgres

mysql:
image: mysql:${VERSION}
image: mysql/mysql-server:${VERSION}
pull: true
environment:
- TZ=Europe/Moscow
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- MYSQL_ROOT_HOST=%
when:
matrix:
DATABASE: mysql
Expand All @@ -68,7 +69,7 @@ services:
matrix:
include:
- {
GO: "golang:1.8", DATABASE: postgres, VERSION: 9.6, REFORM_DRIVER: postgres,
GO: "golang:1.9", DATABASE: postgres, VERSION: 9.6, REFORM_DRIVER: postgres,
REFORM_ROOT_SOURCE: "postgres://postgres@127.0.0.1/template1?sslmode=disable",
REFORM_INIT_SOURCE: "postgres://postgres@127.0.0.1/reform-database?sslmode=disable&TimeZone=UTC",
REFORM_TEST_SOURCE: "postgres://postgres@127.0.0.1/reform-database?sslmode=disable&TimeZone=America/New_York",
Expand All @@ -77,36 +78,36 @@ matrix:

# ANSI mode
- {
GO: "golang:1.8", DATABASE: mysql, VERSION: 5.7, REFORM_DRIVER: mysql,
GO: "golang:1.9", DATABASE: mysql, VERSION: 5.7, REFORM_DRIVER: mysql,
REFORM_ROOT_SOURCE: "root@/mysql",
REFORM_INIT_SOURCE: "root@/reform-database?parseTime=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
REFORM_TEST_SOURCE: "root@/reform-database?parseTime=true&time_zone='America%2FNew_York'&sql_mode='ANSI'"
REFORM_INIT_SOURCE: "root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
REFORM_TEST_SOURCE: "root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='America%2FNew_York'&sql_mode='ANSI'"
}

# TRADITIONAL mode + interpolateParams=true
- {
GO: "golang:1.8", DATABASE: mysql, VERSION: 5.7, REFORM_DRIVER: mysql,
GO: "golang:1.9", DATABASE: mysql, VERSION: 5.7, REFORM_DRIVER: mysql,
REFORM_ROOT_SOURCE: "root@/mysql",
REFORM_INIT_SOURCE: "root@/reform-database?parseTime=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
REFORM_TEST_SOURCE: "root@/reform-database?parseTime=true&time_zone='America%2FNew_York'&sql_mode='TRADITIONAL'&interpolateParams=true"
REFORM_INIT_SOURCE: "root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
REFORM_TEST_SOURCE: "root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='America%2FNew_York'&sql_mode='TRADITIONAL'&interpolateParams=true"
}

- {
GO: "golang:1.8", DATABASE: sqlite3, VERSION: dummy, REFORM_DRIVER: sqlite3,
GO: "golang:1.9", DATABASE: sqlite3, VERSION: dummy, REFORM_DRIVER: sqlite3,
REFORM_ROOT_SOURCE: "/tmp/reform-database.sqlite3",
REFORM_INIT_SOURCE: "/tmp/reform-database.sqlite3",
REFORM_TEST_SOURCE: "/tmp/reform-database.sqlite3"
}

- {
GO: "golang:1.8", DATABASE: mssql, VERSION: latest, REFORM_DRIVER: mssql,
GO: "golang:1.9", DATABASE: mssql, VERSION: latest, REFORM_DRIVER: mssql,
REFORM_ROOT_SOURCE: "server=localhost;user id=sa;password=reform-password123",
REFORM_INIT_SOURCE: "server=localhost;user id=sa;password=reform-password123;database=reform-database",
REFORM_TEST_SOURCE: "server=localhost;user id=sa;password=reform-password123;database=reform-database"
}

- {
GO: "golang:1.8", DATABASE: mssql, VERSION: latest, REFORM_DRIVER: sqlserver,
GO: "golang:1.9", DATABASE: mssql, VERSION: latest, REFORM_DRIVER: sqlserver,
REFORM_ROOT_SOURCE: "sqlserver://sa:reform-password123@localhost",
REFORM_INIT_SOURCE: "sqlserver://sa:reform-password123@localhost?database=reform-database",
REFORM_TEST_SOURCE: "sqlserver://sa:reform-password123@localhost?database=reform-database"
Expand Down
232 changes: 117 additions & 115 deletions .drone.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .drone.yml.sig

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions .github/drone-gen.go
Expand Up @@ -19,19 +19,19 @@ type Driver struct {
}

type Database struct {
ImageName string
ImageVersions []string
Drivers []Driver
Name string
Versions []string
Drivers []Driver
}

func main() {
log.SetFlags(0)
flag.Parse()

goImages := []string{
"golang:1.6",
"golang:1.7",
"golang:1.8",
"golang:1.9",
"captncraig/go-tip",
}

Expand Down Expand Up @@ -68,16 +68,16 @@ func main() {
{
"mysql",
"root@/mysql",
"root@/reform-database?parseTime=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
"root@/reform-database?parseTime=true&time_zone='America%2FNew_York'&sql_mode='ANSI'",
"root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
"root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='America%2FNew_York'&sql_mode='ANSI'",
},

// TRADITIONAL mode + interpolateParams=true
{
"mysql",
"root@/mysql",
"root@/reform-database?parseTime=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
"root@/reform-database?parseTime=true&time_zone='America%2FNew_York'&sql_mode='TRADITIONAL'&interpolateParams=true",
"root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true",
"root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='America%2FNew_York'&sql_mode='TRADITIONAL'&interpolateParams=true",
},
},
},
Expand Down Expand Up @@ -129,7 +129,7 @@ func main() {
for _, d := range db.Drivers {
drivers = append(drivers, d.Name)
}
buf.WriteString(fmt.Sprintf("# %s: %s (drivers: %s)\n", db.ImageName, strings.Join(db.ImageVersions, ", "), strings.Join(drivers, ", ")))
buf.WriteString(fmt.Sprintf("# %s: %s (drivers: %s)\n", db.Name, strings.Join(db.Versions, ", "), strings.Join(drivers, ", ")))
}

buf.WriteString("matrix:\n")
Expand All @@ -138,11 +138,11 @@ func main() {
var count int
for _, g := range goImages {
for _, db := range databases {
for _, v := range db.ImageVersions {
for _, v := range db.Versions {
for _, d := range db.Drivers {
fmt.Fprintf(&buf, " - {\n")
fmt.Fprintf(&buf, " GO: %q, DATABASE: %s, VERSION: %s, REFORM_DRIVER: %s,\n",
g, db.ImageName, v, d.Name)
g, db.Name, v, d.Name)
fmt.Fprintf(&buf, " REFORM_ROOT_SOURCE: %q,\n", d.RootSource)
fmt.Fprintf(&buf, " REFORM_INIT_SOURCE: %q,\n", d.InitSource)
fmt.Fprintf(&buf, " REFORM_TEST_SOURCE: %q", d.TestSource)
Expand Down
Binary file added .github/reform.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.vscode/
.idea/
*.cover
coverage.txt
9 changes: 5 additions & 4 deletions .travis.yml
Expand Up @@ -12,10 +12,10 @@ env:
- TARGET=sqlite3

go:
- 1.6.x
- 1.7.x
- 1.8.x
- tip
- 1.9.x
- master

go_import_path: gopkg.in/reform.v1

Expand All @@ -27,11 +27,12 @@ install:
- make install_deps

script:
- make test $TARGET
- make test
- make $TARGET
- make check

after_success:
- goveralls -coverprofile=$TARGET.cover
- bash <(curl -s https://codecov.io/bash) -X fix

notifications:
webhooks:
Expand Down
41 changes: 27 additions & 14 deletions CHANGELOG.md
@@ -1,41 +1,54 @@
# Changelog

## Not released yet

* `reform-db` command.
* Field with `reform` tag with value `"-"` is ignored now (just like with value `""` and without tag at all).
* `ErrTxDone`.
## v1.3.0 (2017-12-01, https://github.com/go-reform/reform/milestones/v1.3.0)

* Go 1.7+ is now required.
* Added `reform-db` command.
* `init` subcommand may be used to generate Go model files for existing database schema.
* `query` and `exec` subcommands may be used for accessing a database.
* Fields with `reform` tag with value `"-"` are ignored now (just like with value `""` and without tag at all).
* Added [`ErrTxDone`](https://godoc.org/gopkg.in/reform.v1#pkg-variables).
* Added [`DB.DBInterface`](https://godoc.org/gopkg.in/reform.v1#DB.DBInterface).
* Added [`Querier.UpdateView`](https://godoc.org/gopkg.in/reform.v1#Querier.UpdateView).
* `reform` command with `-gofmt=false` flag still formats generated sources with go/format package, without invoking `gofmt`.
Thanks to [João Pereira](https://github.com/joaodrp).
* Added support for `sqlserver` variant of [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) driver.
* Added support for Microsoft SQL Server for Linux.
* We now have a logo! Huge thanks to Natalya Glebova for making it.

## v1.2.1 (2016-09-14, https://github.com/go-reform/reform/milestones/v1.2.1)

* `reform` command now correctly handles non-exported types.
* Querier.Insert now correctly INSERTs records with set non-integer primary keys, even if
dialect uses LastInsertId (MySQL, SQLite3).
* [`Querier.Insert`](https://godoc.org/gopkg.in/reform.v1#Querier.Insert) now correctly INSERTs records with set
non-integer primary keys, even if dialect uses LastInsertId (MySQL, SQLite3).

## v1.2.0 (2016-08-10, https://github.com/go-reform/reform/milestones/v1.2.0)

* Added support for Microsoft SQL Server. Huge thanks to [Aleksey Martynov](https://github.com/AlekseyMartynov).
* Added Querier.InsertColumns.
* Querier.Insert now correctly handles records with only primary key column.
* Added [`Querier.InsertColumns`](https://godoc.org/gopkg.in/reform.v1#Querier.InsertColumns).
* [`Querier.Insert`](https://godoc.org/gopkg.in/reform.v1#Querier.Insert) now correctly handles records with only primary key column.

## v1.1.2 (2016-07-20, https://github.com/go-reform/reform/milestones/v1.1.2)

* `reform` command now correctly ignores type information when it's not used.
This allows one to have fields of any custom types. The only exception is primary key fields,
which are restricted to basic types (numbers and strings).
* Package `gopkg.in/reform.v1/parse` is explicitly documented as internal.
* Package [`gopkg.in/reform.v1/parse`](https://godoc.org/gopkg.in/reform.v1/parse) is explicitly documented as internal.
(It's wasn't really possible to use it.)

## v1.1.1 (2016-07-05, https://github.com/go-reform/reform/milestones/v1.1.1)

* Querier.UpdateColumns no longer allows to update primary key column. This behavior was allowed,
but did not make any sense.
* [`Querier.UpdateColumns`](https://godoc.org/gopkg.in/reform.v1#Querier.UpdateColumns) no longer allows to update
primary key column. This behavior was allowed, but did not make any sense.
* `reform` command now correctly handles pointers to custom types and slices.

## v1.1.0 (2016-07-01, https://github.com/go-reform/reform/milestones/v1.1.0)

* Added Querier.InsertMulti.
* Added DBInterface, TXInterface, NewDBFromInterface, NewTXFromInterface.
* Added [`Querier.InsertMulti`](https://godoc.org/gopkg.in/reform.v1#Querier.InsertMulti).
* Added [`DBInterface`](https://godoc.org/gopkg.in/reform.v1#DBInterface),
[`TXInterface`](https://godoc.org/gopkg.in/reform.v1#TXInterface),
[`NewDBFromInterface`](https://godoc.org/gopkg.in/reform.v1#NewDBFromInterface),
[`NewTXFromInterface`](https://godoc.org/gopkg.in/reform.v1#NewTXFromInterface).

## v1.0.0 (2016-06-22)

Expand Down
18 changes: 10 additions & 8 deletions Makefile
Expand Up @@ -17,26 +17,26 @@ download_deps:
github.com/stretchr/testify/... \
github.com/enodata/faker \
github.com/alecthomas/gometalinter \
github.com/AlekSi/goveralls
github.com/AlekSi/gocoverutil

# download linters
go install -v github.com/alecthomas/gometalinter
gometalinter --install --update --download-only

install_deps:
go install -v github.com/alecthomas/gometalinter \
github.com/AlekSi/goveralls
github.com/AlekSi/gocoverutil
gometalinter --install
go test -i -v

# run unit tests, generate models, install tools
test:
rm -f *.cover
rm -f *.cover coverage.txt
rm -f internal/test/models/*_reform.go
rm -f reform-db/*_reform.go

go install -v gopkg.in/reform.v1/reform
go test $(REFORM_TEST_FLAGS) -coverprofile=parse.cover gopkg.in/reform.v1/parse
go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=parse.cover gopkg.in/reform.v1/parse
go generate -v -x gopkg.in/reform.v1/internal/test/models
go install -v gopkg.in/reform.v1/internal/test/models

Expand All @@ -54,8 +54,10 @@ test-db:
internal/test/sql/data.sql \
internal/test/sql/$(DATABASE)_data.sql \
internal/test/sql/$(DATABASE)_set.sql
go test $(REFORM_TEST_FLAGS) -coverprofile=$(REFORM_DRIVER)-reform-db.cover gopkg.in/reform.v1/reform-db
go test $(REFORM_TEST_FLAGS) -coverprofile=$(REFORM_DRIVER).cover
go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=$(REFORM_DRIVER)-reform-db.cover gopkg.in/reform.v1/reform-db
go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=$(REFORM_DRIVER).cover
gocoverutil -coverprofile=coverage.txt merge *.cover
rm -f *.cover

check:
-gometalinter ./... --deadline=180s --severity=vet:error
Expand All @@ -76,8 +78,8 @@ postgres: test
mysql: export DATABASE = mysql
mysql: export REFORM_DRIVER = mysql
mysql: export REFORM_ROOT_SOURCE = root@/mysql
mysql: export REFORM_INIT_SOURCE = root@/reform-database?parseTime=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true
mysql: export REFORM_TEST_SOURCE = root@/reform-database?parseTime=true&time_zone='America%2FNew_York'
mysql: export REFORM_INIT_SOURCE = root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='UTC'&sql_mode='ANSI'&multiStatements=true
mysql: export REFORM_TEST_SOURCE = root@/reform-database?parseTime=true&clientFoundRows=true&time_zone='America%2FNew_York'
mysql: test
make test-db

Expand Down
44 changes: 35 additions & 9 deletions README.md
Expand Up @@ -5,26 +5,43 @@
[![Travis CI Build Status](https://travis-ci.org/go-reform/reform.svg?branch=v1-stable)](https://travis-ci.org/go-reform/reform)
[![Drone CI Build Status](https://drone.aleksi.io/api/badges/go-reform/reform/status.svg)](https://drone.aleksi.io/go-reform/reform)
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/kbkyjmic461xa7b3/branch/v1-stable?svg=true)](https://ci.appveyor.com/project/AlekSi/reform/branch/v1-stable)
[![Coverage Status](https://coveralls.io/repos/github/go-reform/reform/badge.svg?branch=v1-stable)](https://coveralls.io/github/go-reform/reform?branch=v1-stable)
[![Coverage Report](https://codecov.io/gh/go-reform/reform/branch/v1-stable/graph/badge.svg)](https://codecov.io/gh/go-reform/reform)
[![Go Report Card](https://goreportcard.com/badge/gopkg.in/reform.v1)](https://goreportcard.com/report/gopkg.in/reform.v1)

<a href="https://en.wikipedia.org/wiki/Peter_the_Great"><img align="right" alt="Reform gopher logo" title="Peter the Reformer" src=".github/reform.png"></a>

A better ORM for Go and `database/sql`.

It uses non-empty interfaces, code generation (`go generate`), and initialization-time reflection
as opposed to `interface{}`, type system sidestepping, and runtime reflection. It will be kept simple.

Supported SQL dialects:
* PostgreSQL (tested with [`github.com/lib/pq`](https://github.com/lib/pq)).
* MySQL (tested with [`github.com/go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql)).
* SQLite3 (tested with [`github.com/mattn/go-sqlite3`](https://github.com/mattn/go-sqlite3)).
* Microsoft SQL Server (tested with [`github.com/denisenkom/go-mssqldb`](https://github.com/denisenkom/go-mssqldb)).

| 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/)

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.6+.
2. Install or update `reform` package and command: `go get -u gopkg.in/reform.v1/reform` (see about versioning below).
3. Define a model – `struct` representing a table or view row. For example, store this in file `person.go`:
1. Make sure you are using Go 1.7+. Install or update `reform` package, `reform` and `reform-db` commands
(see about versioning below):

```
go get -u gopkg.in/reform.v1/...
```

2. Use `reform-db` command to generate models for your existing database schema. For example:
```
reform-db -db-driver=sqlite3 -db-source=example.sqlite3 init
```

3. Update generated models or write your own – `struct` representing a table or view row. For example,
store this in file `person.go`:

```go
//go:generate reform
Expand Down Expand Up @@ -136,11 +153,20 @@ Canonical import path is `gopkg.in/reform.v2-unstable`.
## Caveats and limitations

* There should be zero `pk` fields for Struct and exactly one `pk` field for Record.
Composite primary keys are not supported.
Composite primary keys are not supported ([#114](https://github.com/go-reform/reform/issues/114)).
* `pk` field can't be a pointer (`== nil` [doesn't work](https://golang.org/doc/faq#nil_error)).
* Database row can't have a Go's zero value (0, empty string, etc.) in primary key column.


## License

Code is covered by standard MIT-style license. Copyright (c) 2016-2017 Alexey Palazhchenko.
See [LICENSE](LICENSE) for details. Note that generated code is covered by the terms of your choice.

The reform gopher was drawn by Natalya Glebova. Please use it only as reform logo.
It is based on the original design by Renée French, released under [Creative Commons Attribution 3.0 USA license](https://creativecommons.org/licenses/by/3.0/).


## Contributing

See [Contributing Guidelines](.github/CONTRIBUTING.md)
6 changes: 2 additions & 4 deletions appveyor.yml
Expand Up @@ -4,8 +4,6 @@ clone_folder: c:\gopath\src\gopkg.in\reform.v1

environment:
GOPATH: c:\gopath
COVERALLS_TOKEN:
secure: +o9WB0T57udDJzTTSmKMg0O5hrP2e0rAuBL36/foBRYTg8VKccp2G8ovxJi4hsmD
matrix:
- REFORM_SQL_INSTANCE: SQL2008R2SP2
- REFORM_SQL_INSTANCE: SQL2012SP1
Expand All @@ -31,5 +29,5 @@ test_script:
- mingw32-make check

on_success:
- if defined COVERALLS_TOKEN goveralls -coverprofile=mssql.cover -service=
- if defined COVERALLS_TOKEN goveralls -coverprofile=sqlserver.cover -service=
- curl -s -o codecov https://codecov.io/bash
- bash codecov -X fix

0 comments on commit a76bd30

Please sign in to comment.