56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package orm
|
|
|
|
import "fmt"
|
|
|
|
const do_bootstrap = true
|
|
|
|
func TestMain() {
|
|
e, err := Open("postgres://testbed_user:123@localhost/testbed_i_think")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
e.Models(user{}, story{}, band{}, role{})
|
|
if do_bootstrap {
|
|
|
|
err = e.Migrate()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
s := iti_multi()
|
|
u := &author
|
|
u.Favs.Authors = append(u.Favs.Authors, friend)
|
|
_, err = e.Model(&user{}).Create(&friend)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
_, err = e.Model(&user{}).Create(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(&story{}).Create(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
s.Downloads = s.Downloads + 1
|
|
err = e.Model(&story{}).Update(s, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
ns, err := e.Model(&story{}).Where(&story{
|
|
ID: 1,
|
|
}).Populate(PopulateAll).Find()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("%+v", ns)
|
|
}
|