You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a table from a struct containing a member with name "Version" and type other than int results in a panic:
2015/01/27 15:42:57 http: panic serving 127.0.0.1:60027: reflect: call of reflect.Value.Int on string Value
goroutine 23 [running]:
net/http.func·011()
c:/go/src/pkg/net/http/server.go:1100 +0xbe
runtime.panic(0x7059e0, 0xc082007420)
c:/go/src/pkg/runtime/panic.c:248 +0x1d3
reflect.Value.Int(0x697be0, 0xc082016ca0, 0x0, 0x186, 0x77e3d0)
c:/go/src/pkg/reflect/value.go:1053 +0xc3
github.com/coopernurse/gorp.bindPlan.createBindInstance(0xc08205ef00, 0x162, 0xc08201e400, 0x12, 0x20, 0x0, 0x0, 0x0, 0x77e3d0, 0x7, ...)
C:/Users/Christian/Google Drive/Development/go/src/github.com/coopernurse/gorp/gorp.go:289 +0x177
github.com/coopernurse/gorp.(*TableMap).bindInsert(0xc082020b40, 0x761280, 0xc082016c60, 0x0, 0x196, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
C:/Users/Christian/Google Drive/Development/go/src/github.com/coopernurse/gorp/gorp.go:394 +0x6e0
github.com/coopernurse/gorp.insert(0xc0820104e0, 0x181da0, 0xc0820104e0, 0x3a3a38, 0x1, 0x1, 0x0, 0x0)
C:/Users/Christian/Google Drive/Development/go/src/github.com/coopernurse/gorp/gorp.go:1913 +0x2dc
github.com/coopernurse/gorp.(*DbMap).Insert(0xc0820104e0, 0x3a3a38, 0x1, 0x1, 0x0, 0x0)
C:/Users/Christian/Google Drive/Development/go/src/github.com/coopernurse/gorp/gorp.go:955 +0x97
From my POV, this is convention over configuration, just the wrong way around.
My proposed solution is to disable setting the version ColMap in AddTable(i interface{}), forcing the developer to manually set the version column name by using SetVersionCol(). This is a crude fix, but it shows the problem and how to solve it.
Update gorp_test.go
Fixed tests by using SetVersionCol on person tablemap
Remove maintainers notice (since PR is closed). Add google group and
irc channel to Help/Support section
Use #gorp as channel
Add gopkg.in versioned releases information.
Also made the markdown headings consistently use prefixed #'s, no suffix.
Change coopernurse/gorp to go-gorp/gorp in Makefile, godoc and comments.
Extended the Exec functionality so that it can be used with named parameters.
Unexport the Executor
Removed version column detection in readStructColumns
Update gorp.go
Added warning telling users that automatic mapping of Version struct members to version column in database (optimistic locking) will be removed in V2
Update gorp.go
Changed log output to stderr
Added migration guide and notes
Added migration guide and notes about change in behaviour in Optimistic locking.
Update README.md
Update gorp.go
Corrected vim gone wild
I hesitate to call gorp an ORM. Go doesn't really have objects, at least
23
-
not in the classic Smalltalk/Java sense. There goes the "O". gorp doesn't
24
-
know anything about the relationships between your structs (at least not
25
-
yet). So the "R" is questionable too (but I use it in the name because,
5
+
I hesitate to call gorp an ORM. Go doesn't really have objects, at least
6
+
not in the classic Smalltalk/Java sense. There goes the "O". gorp doesn't
7
+
know anything about the relationships between your structs (at least not
8
+
yet). So the "R" is questionable too (but I use it in the name because,
26
9
well, it seemed more clever).
27
10
28
11
The "M" is alive and well. Given some Go structs and a database, gorp
29
12
should remove a fair amount of boilerplate busy-work from your code.
30
13
31
-
I hope that gorp saves you time, minimizes the drudgery of getting data
32
-
in and out of your database, and helps your code focus on algorithms,
14
+
I hope that gorp saves you time, minimizes the drudgery of getting data
15
+
in and out of your database, and helps your code focus on algorithms,
33
16
not infrastructure.
34
17
35
18
* Bind struct fields to table columns via API or tag
@@ -47,21 +30,33 @@ not infrastructure.
47
30
* Use positional or named bind parameters in custom SELECT queries
48
31
* Optional optimistic locking using a version column (for update/deletes)
49
32
50
-
## Installation ##
33
+
## Installation
51
34
52
35
# install the library:
53
-
go get github.com/go-gorp/gorp
36
+
go get gopkg.in/gorp.v1
54
37
55
38
// use in your .go code:
56
39
import (
57
-
"github.com/go-gorp/gorp"
40
+
"gopkg.in/gorp.v1"
58
41
)
59
42
60
-
## API Documentation ##
43
+
## Versioning
44
+
45
+
This project provides a stable release (v1.x tags) and a bleeding edge codebase (master).
46
+
47
+
`gopkg.in/gorp.v1` points to the latest v1.x tag. The API's for v1 are stable and shouldn't change. Development takes place at the master branch. Althought the code in master should always compile and test successfully, it might break API's. We aim to maintain backwards compatibility, but API's and behaviour might be changed to fix a bug. Also note that API's that are new in the master branch can change until released as v2.
61
48
62
-
Full godoc output from the latest code in master is available here:
49
+
If you want to use bleeding edge, use `github.com/go-gorp/gorp` as import path.
See the `test_all.sh` script for examples of all 3 databases. This is the script I run
650
647
locally to test the library.
651
648
652
-
## Performance ##
649
+
## Performance
650
+
651
+
gorp uses reflection to construct SQL queries and bind parameters. See the BenchmarkNativeCrud vs BenchmarkGorpCrud in gorp_test.go for a simple perf test. On my MacBook Pro gorp is about 2-3% slower than hand written SQL.
652
+
653
+
## Migration guide
654
+
#### Pre-v2 to v2
655
+
Automatic mapping of the version column used in optimistic locking has been removed as it could cause problems if the type was not int. The version column must now explicitly be set with tablemap.SetVersionCol().
656
+
657
+
## Help/Support
653
658
654
-
gorp uses reflection to construct SQL queries and bind parameters. See the BenchmarkNativeCrud vs BenchmarkGorpCrud in gorp_test.go for a simple perf test. On my MacBook Pro gorp is about 2-3% slower than hand written SQL.
0 commit comments