Skip to content

Instantly share code, notes, and snippets.

@ainar-g
Created November 5, 2013 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ainar-g/7323528 to your computer and use it in GitHub Desktop.
Save ainar-g/7323528 to your computer and use it in GitHub Desktop.
Program that causes panic on db.CreateTable(User{}).
package main
import (
. `fmt`
`github.com/jinzhu/gorm`
_ `github.com/lib/pq`
`time`
)
func panicOn(e error) {
if e != nil {
panic(Sprintf("An error occured: %s\n", e.Error()))
}
}
func main() {
Println(`Started.`)
type User struct {
Id int64
Login string
Password string
CreatedAt time.Time // Works when deleting these
UpdatedAt time.Time // two lines.
DeletedAt time.Time
}
const connStr = "user=player password=player dbname=playground"
db, e := gorm.Open("postgres", connStr)
panicOn(e)
db.SetPool(10)
// db.DropTable(&User{}) works always.
db.DropTable(User{})
// db.CreateTable(&User{}) works always.
e = db.CreateTable(User{}).Error
panicOn(e)
user := &User{Login: `Foo`, Password: `f00B4R`}
e = db.Save(user).Error
panicOn(e)
Println(`Finished.`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment