Commit e3bb9d17 authored by Jason Moiron's avatar Jason Moiron

add time.Time support, use timestamp w/ time zone,...

add time.Time support, use timestamp w/ time zone, abc01bc429c1b1c264087711b823e578ba666d3b and e5a6512ec776ecc8373e11165f992a8a91ac4ae4 from gorp upstream
parent 0e5562cc
......@@ -52,11 +52,11 @@ Since modl is a gorp fork, here are some of its major behavioral differences:
To use the `test-all` script, set the following environment variables:
```sh
# mysql DSN, like "modltest/modltest/modltest"
MODL_MYSQL_DSN="dbname/username/password"
# mysql DSN, like:
MODL_MYSQL_DSN="username:password@/dbname"
# postgres DSN, like:
MODL_POSTGRES_DSN="username=dbname password=pw dbname=dbname ssl-node=disable"
MODL_POSTGRES_DSN="username=username password=pw dbname=dbname ssl-node=disable"
# sqlite DSN, which is a path
MODL_SQLITE_DSN="/dev/shm/modltest.db"
......
......@@ -92,6 +92,8 @@ func (d SqliteDialect) ToSqlType(col *ColumnMap) string {
return "integer"
case "NullableBytes":
return "blob"
case "Time", "NullTime":
return "datetime"
}
// sqlite ignores maxsize, so we will do that here too
......@@ -180,6 +182,8 @@ func (d PostgresDialect) ToSqlType(col *ColumnMap) string {
return "smallint"
case "NullableBytes":
return "bytea"
case "Time", "Nulltime":
return "timestamp with time zone"
}
maxsize := col.MaxSize
......@@ -279,6 +283,8 @@ func (m MySQLDialect) ToSqlType(col *ColumnMap) string {
return "tinyint"
case "NullableBytes":
return "mediumblob"
case "Time", "NullTime":
return "datetime"
}
maxsize := col.MaxSize
......
......@@ -702,6 +702,7 @@ func initDbMap() *DbMap {
dbmap.AddTableWithName(Invoice{}, "invoice_test").SetKeys(true, "id")
dbmap.AddTableWithName(Person{}, "person_test").SetKeys(true, "id")
dbmap.AddTableWithName(WithIgnoredColumn{}, "ignored_column_test").SetKeys(true, "id")
dbmap.AddTableWithName(WithTime{}, "time_test").SetKeys(true, "Id")
err := dbmap.CreateTables()
if err != nil {
panic(err)
......@@ -771,6 +772,37 @@ func TestQuoteTableNames(t *testing.T) {
logBuffer.Reset()
}
type WithTime struct {
Id int64
Time time.Time
}
func TestWithTime(t *testing.T) {
dbmap := initDbMap()
defer dbmap.DropTables()
// FIXME: there seems to be a bug with go-sql-driver and timezones?
// MySQL doesn't have any timestamp support, but since it is not
// sending any, the scan assumes UTC, so the scanner should
// probably convert to UTC before storing. Also, note that time.Time
// support requires a special bit to be added to the DSN
t1, err := time.Parse("2006-01-02 15:04:05 -0700 MST",
"2013-08-09 21:30:43 +0000 UTC")
if err != nil {
t.Fatal(err)
}
w1 := WithTime{1, t1}
dbmap.Insert(&w1)
w2 := WithTime{}
dbmap.Get(&w2, w1.Id)
if w1.Time.UnixNano() != w2.Time.UnixNano() {
t.Errorf("%v != %v", w1, w2)
}
}
func initDbMapNulls() *DbMap {
dbmap := newDbMap()
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
......
......@@ -20,7 +20,7 @@ if [ -f "./environ" ]; then
. ./environ
fi
set -e
# set -e
if [ -n "$MODL_MYSQL_DSN" ]; then
export MODL_TEST_DSN="$MODL_MYSQL_DSN"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment