Skip to content

Commit 65378da

Browse files
authored
Merge pull request #402 from go-gorp/nulltime-fix
Fix gorp's NullTime and test logic for recent versions of go
2 parents 95866f2 + 11ba757 commit 65378da

30 files changed

+142
-339
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ env:
1717
global:
1818
- secure: RriLxF6+2yMl67hdVv8ImXlu0h62mhcpqjaOgYNU+IEbUQ7hx96CKY6gkpYubW3BgApvF5RH6j3+HKvh2kGp0XhDOYOQCODfBSaSipZ5Aa5RKjsEYLtuVIobvJ80awR9hUeql69+WXs0/s72WThG0qTbOUY4pqHWfteeY235hWM=
1919

20+
install:
21+
- go get -t -d
22+
- go get -t -d -tags integration
23+
2024
before_script:
2125
- mysql -e "CREATE DATABASE gorptest;"
2226
- mysql -u root -e "GRANT ALL ON gorptest.* TO gorptest@localhost IDENTIFIED BY 'gorptest'"
@@ -28,6 +32,5 @@ before_script:
2832
- go get github.com/go-sql-driver/mysql
2933
- go get golang.org/x/tools/cmd/cover
3034
- go get github.com/mattn/goveralls
31-
- go get github.com/onsi/ginkgo/ginkgo
3235

3336
script: ./test_all.sh

column.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import "reflect"

gorp_go18_test.go context_test.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
//
12-
13-
// +build go1.8
5+
// +build integration
146

157
package gorp_test
168

db.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

db_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
5+
// +build integration
116

127
package gorp_test
138

dialect.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

dialect_mysql.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

dialect_mysql_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
5+
// +build !integration
116

127
package gorp_test
138

dialect_oracle.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

dialect_postgres.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

dialect_postgres_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
5+
// +build !integration
116

127
package gorp_test
138

dialect_sqlite.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

dialect_sqlserver.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

doc.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2012 James Cooper. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Package gorp provides a simple way to marshal Go structs to and from
6+
// SQL databases. It uses the database/sql package, and should work with any
7+
// compliant database/sql driver.
8+
//
9+
// Source code and project home:
10+
// https://github.com/go-gorp/gorp
11+
package gorp

errors.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
125
package gorp
136

147
import (

gorp.go

+61-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
// Package gorp provides a simple way to marshal Go structs to and from
6-
// SQL databases. It uses the database/sql package, and should work with any
7-
// compliant database/sql driver.
8-
//
9-
// Source code and project home:
10-
// https://github.com/go-gorp/gorp
11-
//
125
package gorp
136

147
import (
@@ -183,6 +176,19 @@ func extractDbMap(e SqlExecutor) *DbMap {
183176
return nil
184177
}
185178

179+
// executor exposes the sql.DB and sql.Tx functions so that it can be used
180+
// on internal functions that need to be agnostic to the underlying object.
181+
type executor interface {
182+
Exec(query string, args ...interface{}) (sql.Result, error)
183+
Prepare(query string) (*sql.Stmt, error)
184+
QueryRow(query string, args ...interface{}) *sql.Row
185+
Query(query string, args ...interface{}) (*sql.Rows, error)
186+
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
187+
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
188+
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
189+
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
190+
}
191+
186192
func extractExecutorAndContext(e SqlExecutor) (executor, context.Context) {
187193
switch m := e.(type) {
188194
case *DbMap:
@@ -616,3 +622,51 @@ func insert(m *DbMap, exec SqlExecutor, list ...interface{}) error {
616622
}
617623
return nil
618624
}
625+
626+
func exec(e SqlExecutor, query string, args ...interface{}) (sql.Result, error) {
627+
executor, ctx := extractExecutorAndContext(e)
628+
629+
if ctx != nil {
630+
return executor.ExecContext(ctx, query, args...)
631+
}
632+
633+
return executor.Exec(query, args...)
634+
}
635+
636+
func prepare(e SqlExecutor, query string) (*sql.Stmt, error) {
637+
executor, ctx := extractExecutorAndContext(e)
638+
639+
if ctx != nil {
640+
return executor.PrepareContext(ctx, query)
641+
}
642+
643+
return executor.Prepare(query)
644+
}
645+
646+
func queryRow(e SqlExecutor, query string, args ...interface{}) *sql.Row {
647+
executor, ctx := extractExecutorAndContext(e)
648+
649+
if ctx != nil {
650+
return executor.QueryRowContext(ctx, query, args...)
651+
}
652+
653+
return executor.QueryRow(query, args...)
654+
}
655+
656+
func query(e SqlExecutor, query string, args ...interface{}) (*sql.Rows, error) {
657+
executor, ctx := extractExecutorAndContext(e)
658+
659+
if ctx != nil {
660+
return executor.QueryContext(ctx, query, args...)
661+
}
662+
663+
return executor.Query(query, args...)
664+
}
665+
666+
func begin(m *DbMap) (*sql.Tx, error) {
667+
if m.ctx != nil {
668+
return m.Db.BeginTx(m.ctx, nil)
669+
}
670+
671+
return m.Db.Begin()
672+
}

gorp_go17.go

-54
This file was deleted.

0 commit comments

Comments
 (0)