Created
November 5, 2013 18:16
-
-
Save ainar-g/7323528 to your computer and use it in GitHub Desktop.
Program that causes panic on db.CreateTable(User{}).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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