65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package orm
|
|
|
|
import "fmt"
|
|
|
|
const do_bootstrap = false
|
|
|
|
func TestMain() {
|
|
e, err := Open("postgres://testbed_user:123@localhost/testbed_i_think")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
u := author()
|
|
s := iti_multi(u)
|
|
e.Models(user{}, story{}, band{}, role{})
|
|
if do_bootstrap {
|
|
|
|
err = e.Migrate()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
f := friend()
|
|
err = e.Model(&user{}).Create(&f)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = e.Model(&user{}).Create(&u)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
u.Favs.Authors = append(u.Favs.Authors, f)
|
|
err = e.Model(&user{}).Save(&u)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = e.Model(&band{}).Create(&bodom)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = e.Model(&band{}).Create(&diamondHead)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
err = e.Model(&user{}).Where("ID = ?", s.Author.ID).Find(&s.Author)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = e.Model(&story{}).Save(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
s.Downloads = s.Downloads + 1
|
|
err = e.Model(&story{}).Save(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var ns story
|
|
err = e.Model(&story{}).Where("ID = ?", 1).Populate(PopulateAll, "Chapters.Bands").Find(&ns)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("%+v", ns)
|
|
}
|