本文整理汇总了Golang中github.com/coopernurse/gorp.SqlExecutor.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang SqlExecutor.Exec方法的具体用法?Golang SqlExecutor.Exec怎么用?Golang SqlExecutor.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coopernurse/gorp.SqlExecutor
的用法示例。
在下文中一共展示了SqlExecutor.Exec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostInsert
// PostInsert ensures that the Attendees list is set in the database
func (i *Invite) PostInsert(s gorp.SqlExecutor) error {
query := "insert into profile_invite values ($1, $2, $3)"
for _, a := range i.Attendees {
_, err := s.Exec(query, a.Id, i.Id, string(a.Status))
if err != nil {
return err
}
}
return nil
}
示例2: PostUpdate
// PostUpdate clears Flag and Utype information and then sets it correctly. This
// could definitely be a bit lighter-touch, in the sense that we could diff the
// rows against the struct and only delete and insert some rows, but this might
// actually be faster anyway (and PostgreSQL doesn't have a handy upsert syntax,
// so, whatever).
func (p *Profile) PostUpdate(s gorp.SqlExecutor) error {
var err error
// flags
_, err = s.Exec("delete from profile_flag where profile = $1", p.Id)
if err != nil {
return err
}
for _, flag := range p.Flags {
_, err = s.Exec("insert into profile_flag values ($1, $2)", flag.Id, p.Id)
if err != nil {
return err
}
}
// types
if len(p.Utypes) == 0 {
return errors.New("Profile utype cannot be empty")
}
_, err = s.Exec("delete from profile_utype where profile = $1", p.Id)
if err != nil {
return err
}
for _, t := range p.Utypes {
_, err = s.Exec("insert into profile_utype values ($1, $2)", t.Id, p.Id)
if err != nil {
return err
}
}
return nil
}
示例3: updateCategoires
func (m *Member) updateCategoires(s gorp.SqlExecutor) error {
// delete existing categories
format := "delete from " + TableNameCategoryMember + " where memberid = ?"
if _, err := s.Exec(format, m.ID); err != nil {
return err
}
// create new categories
for _, catId := range m.CategoryIds {
catMem := NewCategoryMember(catId, m.ID)
if err := s.Insert(catMem); err != nil {
return err
}
}
return nil
}