Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed NullTime returns always invalid on sqlite3. #203

Merged
merged 62 commits into from Mar 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
32a45d9
Merge branch 'release/v1.2.1'
coopernurse Nov 19, 2013
d2579dd
Merge branch 'release/v1.3'
Dec 16, 2013
176b9dd
Update docs for SelectOne to reflect the code.
joho Dec 28, 2013
08e1d8c
Merge branch 'release/v1.4'
Jan 18, 2014
242be3e
Merge branch 'release/v1.5'
Mar 10, 2014
c7d1aec
Merge branch 'release/v1.6'
May 23, 2014
31a7c02
columnToFieldIndex: revert b5ce3b9 change, as it breaks tag mapping w…
May 28, 2014
5d19ebd
Merge branch 'release/v1.7'
coopernurse Sep 6, 2014
236e138
#211 - add call for maintainers to README
coopernurse Dec 8, 2014
3643e90
Update README.md with new repo path.
GeertJohan Jan 22, 2015
1927cbe
Merge branch 'develop'
GeertJohan Jan 22, 2015
0a7ddd4
Merge branch 'develop'
GeertJohan Jan 22, 2015
e9eed2f
Disable "automagic" mapping of tablemap.Version
sqdk Jan 27, 2015
b943032
Update gorp_test.go
sqdk Jan 27, 2015
305390f
Merge pull request #1 from sqdk/patch-1
sqdk Jan 28, 2015
c9804f2
Remove maintainers notice (since PR is closed). Add google group and
benprew Feb 1, 2015
e21f5e4
Use #gorp as channel
benprew Feb 1, 2015
013813e
Merge pull request #216 from go-gorp/update-readme
benprew Feb 1, 2015
8387985
Add gopkg.in versioned releases information.
Feb 1, 2015
bb0da2f
Merge pull request #217 from go-gorp/gopkg-in-releases
Feb 1, 2015
0160e43
Change coopernurse/gorp to go-gorp/gorp in Makefile, godoc and comments.
Feb 1, 2015
188d84c
Update gorp.go
sqdk Feb 3, 2015
0b23b74
Update gorp.go
sqdk Feb 3, 2015
c5d4bb0
Update gorp.go
sqdk Feb 4, 2015
6356ca9
Extended the Exec functionality so that it can be used with named par…
billmccord Sep 18, 2014
db61a53
Unexport the Executor
billmccord Feb 12, 2015
5f5df32
Merge branch '194-named-params' of https://github.com/billmccord/gorp…
GeertJohan Feb 12, 2015
f7757e0
Merge branch 'billmccord-194-named-params'
GeertJohan Feb 12, 2015
9a61cb5
Merge pull request #2 from sqdk/sqdk-patch-2-warn
sqdk Feb 16, 2015
7bd0b39
Merge remote-tracking branch 'upstream/master'
Feb 16, 2015
283ba78
Merge pull request #3 from sqdk/patch-1
sqdk Feb 16, 2015
c299ec8
Removed version column detection in readStructColumns
Feb 16, 2015
2ab994a
Merge branch 'master' of https://github.com/sqdk/gorp
Feb 16, 2015
cfba4f3
Added migration guide and notes
sqdk Feb 16, 2015
27cc43a
Update README.md
sqdk Feb 16, 2015
50cd598
Update gorp.go
sqdk Feb 16, 2015
6594ec3
Corrected vim gone wild
sqdk Feb 16, 2015
99989ab
Update .travis.yml
sqdk Feb 16, 2015
b9a80d0
Update .travis.yml
sqdk Feb 17, 2015
6dad9fa
Update .travis.yml
sqdk Feb 17, 2015
f2a9a30
Add NullTime in Postgres ToSqlType
GeertJohan Feb 17, 2015
a2b19fb
Fix old description about GORP_TEST_DIALECT in README.md
umisama Feb 18, 2015
78306d1
Fix expand query on NullTime or other structs.
umisama Feb 18, 2015
ad7cc6c
Merge pull request #230 from umisama/patch-3
Feb 26, 2015
1829ef3
Update README.md regarding Go supported versions.
GeertJohan Feb 26, 2015
37e3d43
Travis build: drop go1.1, add go1.2, go1.3 and go1.4
GeertJohan Feb 26, 2015
e66dcda
Merge pull request #231 from umisama/patch-4
Feb 26, 2015
9992d76
Merge pull request #234 from GeertJohan/supported-go-versions
Feb 26, 2015
6ac74a0
Readme: latest > last, minor > major.
GeertJohan Feb 26, 2015
04b2c71
Disable "automagic" mapping of tablemap.Version
sqdk Jan 27, 2015
509244d
Merge branch 'patch-1' of https://github.com/sqdk/gorp into patch-1
Feb 26, 2015
7d4ea60
Merge remote-tracking branch 'upstream/master' into patch-1
Feb 26, 2015
562843a
Removed unnecessary imports
Feb 26, 2015
6c5ace9
Add NullTime in Postgres ToSqlType
GeertJohan Feb 17, 2015
46f15d0
Fix old description about GORP_TEST_DIALECT in README.md
umisama Feb 18, 2015
a17e1eb
Fix expand query on NullTime or other structs.
umisama Feb 18, 2015
2c4a968
Update README.md regarding Go supported versions.
GeertJohan Feb 26, 2015
8ee131d
Travis build: drop go1.1, add go1.2, go1.3 and go1.4
GeertJohan Feb 26, 2015
d3f0a40
Squash
GeertJohan Feb 26, 2015
dcba119
Merge branch 'patch-1' of https://github.com/sqdk/gorp into patch-1
Feb 26, 2015
aa5e410
Merge pull request #224 from sqdk/patch-1
Feb 26, 2015
d376e08
Fixed NullTime returns always invalid on sqlite3.
umisama Oct 17, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
@@ -1,6 +1,8 @@
language: go
go:
- 1.1
- 1.2
- 1.3
- 1.4
- tip

services:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
@@ -1,6 +1,6 @@
include $(GOROOT)/src/Make.inc

TARG = github.com/coopernurse/gorp
TARG = github.com/go-gorp/gorp
GOFILES = gorp.go dialect.go

include $(GOROOT)/src/Make.pkg
131 changes: 72 additions & 59 deletions README.md
@@ -1,35 +1,18 @@
# Go Relational Persistence #
# Go Relational Persistence

[![build status](https://secure.travis-ci.org/go-gorp/gorp.png)](http://travis-ci.org/go-gorp/gorp)

## Call for Maintainers

Dec 7 2014

I've been slacking on keeping up with issues and PRs. I know there are
many of you out there who have active forks and some good ideas on how to
push the project forward. If you'd like to step up and either be added as
a committer to this repo, or would like to become the new canonical fork
of the project, please comment on #211 here:

https://github.com/go-gorp/gorp/issues/211

Thank you!


----

I hesitate to call gorp an ORM. Go doesn't really have objects, at least
not in the classic Smalltalk/Java sense. There goes the "O". gorp doesn't
know anything about the relationships between your structs (at least not
yet). So the "R" is questionable too (but I use it in the name because,
I hesitate to call gorp an ORM. Go doesn't really have objects, at least
not in the classic Smalltalk/Java sense. There goes the "O". gorp doesn't
know anything about the relationships between your structs (at least not
yet). So the "R" is questionable too (but I use it in the name because,
well, it seemed more clever).

The "M" is alive and well. Given some Go structs and a database, gorp
should remove a fair amount of boilerplate busy-work from your code.

I hope that gorp saves you time, minimizes the drudgery of getting data
in and out of your database, and helps your code focus on algorithms,
I hope that gorp saves you time, minimizes the drudgery of getting data
in and out of your database, and helps your code focus on algorithms,
not infrastructure.

* Bind struct fields to table columns via API or tag
Expand All @@ -47,21 +30,40 @@ not infrastructure.
* Use positional or named bind parameters in custom SELECT queries
* Optional optimistic locking using a version column (for update/deletes)

## Installation ##
## Installation

# install the library:
go get github.com/go-gorp/gorp
go get gopkg.in/gorp.v1

// use in your .go code:
import (
"github.com/go-gorp/gorp"
"gopkg.in/gorp.v1"
)

## API Documentation ##
## Versioning

This project provides a stable release (v1.x tags) and a bleeding edge codebase (master).

`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.

If you want to use bleeding edge, use `github.com/go-gorp/gorp` as import path.

Full godoc output from the latest code in master is available here:
## API Documentation

http://godoc.org/github.com/go-gorp/gorp
Full godoc output from the latest v1 release is available here:

https://godoc.org/gopkg.in/gorp.v1

For the latest code in master:

https://godoc.org/github.com/go-gorp/gorp

## Supported Go versions

This package is compatible with the last 2 major versions of Go, at this time `1.3` and `1.4`.

Any earlier versions are only supported on a best effort basis and can be dropped any time.
Go has a great compatibility promise. Upgrading your program to a newer version of Go should never really be a problem.

## Quickstart

Expand All @@ -70,7 +72,7 @@ package main

import (
"database/sql"
"github.com/go-gorp/gorp"
"gopkg.in/gorp.v1"
_ "github.com/mattn/go-sqlite3"
"log"
"time"
Expand Down Expand Up @@ -183,9 +185,9 @@ func checkErr(err error, msg string) {
}
```

## Examples ##
## Examples

### Mapping structs to tables ###
### Mapping structs to tables

First define some types:

Expand Down Expand Up @@ -248,7 +250,7 @@ t2 := dbmap.AddTableWithName(Person{}, "person_test").SetKeys(true, "Id")
t3 := dbmap.AddTableWithName(Product{}, "product_test").SetKeys(true, "Id")
```

### Struct Embedding ###
### Struct Embedding

gorp supports embedding structs. For example:

Expand Down Expand Up @@ -287,7 +289,7 @@ dbmap.CreateTablesIfNotExists()
dbmap.DropTables()
```

### SQL Logging ###
### SQL Logging

Optionally you can pass in a logger to trace all SQL statements.
I recommend enabling this initially while you're getting the feel for what
Expand All @@ -306,7 +308,7 @@ dbmap.TraceOn("[gorp]", log.New(os.Stdout, "myapp:", log.Lmicroseconds))
dbmap.TraceOff()
```

### Insert ###
### Insert

```go
// Must declare as pointers so optional callback hooks
Expand All @@ -322,7 +324,7 @@ err := dbmap.Insert(inv1, inv2)
fmt.Printf("inv1.Id=%d inv2.Id=%d\n", inv1.Id, inv2.Id)
```

### Update ###
### Update

Continuing the above example, use the `Update` method to modify an Invoice:

Expand All @@ -331,7 +333,7 @@ Continuing the above example, use the `Update` method to modify an Invoice:
count, err := dbmap.Update(inv1)
```

### Delete ###
### Delete

If you have primary key(s) defined for a struct, you can use the `Delete`
method to remove rows:
Expand All @@ -340,7 +342,7 @@ method to remove rows:
count, err := dbmap.Delete(inv1)
```

### Select by Key ###
### Select by Key

Use the `Get` method to fetch a single row by primary key. It returns
nil if no row is found.
Expand All @@ -351,9 +353,9 @@ obj, err := dbmap.Get(Invoice{}, 99)
inv := obj.(*Invoice)
```

### Ad Hoc SQL ###
### Ad Hoc SQL

#### SELECT ####
#### SELECT

`Select()` and `SelectOne()` provide a simple way to bind arbitrary queries to a slice
or a single struct.
Expand Down Expand Up @@ -413,7 +415,7 @@ if reflect.DeepEqual(list[0], expected) {
}
```

#### SELECT string or int64 ####
#### SELECT string or int64

gorp provides a few convenience methods for selecting a single string or int64.

Expand All @@ -426,7 +428,7 @@ s, err := dbmap.SelectStr("select name from foo where blah=?", blahVal)

```

#### Named bind parameters ####
#### Named bind parameters

You may use a map or struct to bind parameters by name. This is currently
only supported in SELECT queries.
Expand All @@ -438,15 +440,15 @@ _, err := dbm.Select(&dest, "select * from Foo where name = :name and age = :age
})
```

#### UPDATE / DELETE ####
#### UPDATE / DELETE

You can execute raw SQL if you wish. Particularly good for batch operations.

```go
res, err := dbmap.Exec("delete from invoice_test where PersonId=?", 10)
```

### Transactions ###
### Transactions

You can batch operations into a transaction:

Expand All @@ -467,7 +469,7 @@ func InsertInv(dbmap *DbMap, inv *Invoice, per *Person) error {
}
```

### Hooks ###
### Hooks

Use hooks to update data before/after saving to the db. Good for timestamps:

Expand Down Expand Up @@ -512,7 +514,9 @@ Full list of hooks that you can implement:

func (p *MyStruct) PostUpdate(s gorp.SqlExecutor) error

### Optimistic Locking ###
### Optimistic Locking

#### Note that this behaviour has changed in v2. See [Migration Guide](#migration-guide).

gorp provides a simple optimistic locking feature, similar to Java's JPA, that
will raise an error if you try to update/delete a row whose `version` column
Expand Down Expand Up @@ -565,7 +569,7 @@ if ok {
}
```

## Database Drivers ##
## Database Drivers

gorp uses the Go 1 `database/sql` package. A full list of compliant drivers is available here:

Expand All @@ -590,9 +594,9 @@ Note that these databases are not covered by CI and I (@coopernurse) have no goo
test them locally. So please try them and send patches as needed, but expect a bit more
unpredicability.

## Known Issues ##
## Known Issues

### SQL placeholder portability ###
### SQL placeholder portability

Different databases use different strings to indicate variable placeholders in
prepared SQL statements. Unlike some database abstraction layers (such as JDBC),
Expand All @@ -617,7 +621,7 @@ err := dbmap.SelectOne(&val, "select * from foo where id = :id",
map[string]interface{} { "id": 30})
```

### time.Time and time zones ###
### time.Time and time zones

gorp will pass `time.Time` fields through to the `database/sql` driver, but note that
the behavior of this type varies across database drivers.
Expand All @@ -627,7 +631,7 @@ MySQL users should be especially cautious. See: https://github.com/ziutek/mymys
To avoid any potential issues with timezone/DST, consider using an integer field for time
data and storing UNIX time.

## Running the tests ##
## Running the tests

The included tests may be run against MySQL, Postgresql, or sqlite3.
You must set two environment variables so the test code knows which driver to
Expand All @@ -645,23 +649,32 @@ go test
go test -bench="Bench" -benchtime 10
```

Valid `GORP_TEST_DIALECT` values are: "mysql", "postgres", "sqlite3"
Valid `GORP_TEST_DIALECT` values are: "mysql"(for mymysql), "gomysql"(for go-sql-driver), "postgres", "sqlite"
See the `test_all.sh` script for examples of all 3 databases. This is the script I run
locally to test the library.

## Performance ##
## Performance

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.

## Migration guide
#### Pre-v2 to v2
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().

## Help/Support

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.
IRC: #gorp
Mailing list: gorp-dev@googlegroups.com
Bugs/Enhancements: Create a github issue

## Pull requests / Contributions

Contributions are very welcome. Please follow these guidelines:

* Fork the `develop` branch and issue pull requests targeting the `develop` branch
* If you don't do this, I'll likely cherry pick your commit into develop
* If you are adding an enhancement, please open an issue first with your proposed change.
* Fork the `master` branch and issue pull requests targeting the `master` branch
* If you are adding an enhancement, please open an issue first with your proposed change.
* Changes that break backwards compatibility in the public API are only accepted after we
discuss on a GitHub issue for a while.
discuss on a GitHub issue for a while.

Thanks!

Expand Down
2 changes: 1 addition & 1 deletion dialect.go
Expand Up @@ -229,7 +229,7 @@ func (d PostgresDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr boo
return "double precision"
case "NullBool":
return "boolean"
case "Time":
case "Time", "NullTime":
return "timestamp with time zone"
}

Expand Down