Skip to content

Commit

Permalink
Fix PRIMARY KEY detection for MySQL (#241)
Browse files Browse the repository at this point in the history
* Fix PRIMARY KEY detection for MySQL

* Fix select query condition

* Add proper tests

* Minor tweaks

* Silence new linter warnings
  • Loading branch information
AlekSi committed Aug 31, 2020
1 parent f9331a1 commit 213ddec
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ linters-settings:
linters:
enable-all: true
disable:
- goerr113 # reform v1 should not wrap errors to keep SemVer compatibility
- gomnd # too annoying
- lll # too annoying
- nlreturn # too annoying
- testpackage # too annoying
- wsl # too annoying

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ env-up-detach: ## Start development environment in the
env-down: ## Stop development environment.
docker-compose down --volumes --remove-orphans

env-mysql: ## Run mysql client.
docker exec -ti reform_mysql mysql

test: ## Run all tests and gather coverage.
make test-unit

Expand Down
7 changes: 2 additions & 5 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,8 @@ func (s *ReformSuite) TestTimezones() {
q := fmt.Sprintf(`INSERT INTO projects (id, name, start) VALUES `+
`('11', '11', %s), ('12', '12', %s), ('13', '13', %s), ('14', '14', %s)`,
s.q.Placeholder(1), s.q.Placeholder(2), s.q.Placeholder(3), s.q.Placeholder(4))

withIdentityInsert(s.T(), s.q, "people", func() {
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
s.NoError(err)
})
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
s.NoError(err)

q = `SELECT start, start FROM projects WHERE id IN ('11', '12', '13', '14') ORDER BY id`
rows, err := s.q.Query(q)
Expand Down
17 changes: 12 additions & 5 deletions internal/test/models/good.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:stylecheck
package models

import (
Expand Down Expand Up @@ -106,17 +107,23 @@ type PersonProject struct {
ProjectID string `reform:"project_id"`
}

// reform:id_only
type IDOnly struct {
ID int32 `reform:"id,pk"`
}

//reform:constraints
type Constraints struct {
I int32 `reform:"i"`
ID string `reform:"id,pk"`
}

//reform:legacy.people
type LegacyPerson struct {
ID int32 `reform:"id,pk"`
Name *string `reform:"name"`
}

// reform:id_only
type IDOnly struct {
ID int32 `reform:"id,pk"`
}

// check interfaces
var (
_ reform.BeforeInserter = (*Person)(nil)
Expand Down
Loading

0 comments on commit 213ddec

Please sign in to comment.