本文整理汇总了Golang中periwinkle.Tx.Save方法的典型用法代码示例。如果您正苦于以下问题:Golang Tx.Save方法的具体用法?Golang Tx.Save怎么用?Golang Tx.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类periwinkle.Tx
的用法示例。
在下文中一共展示了Tx.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Save
func (o *Group) Save(db *periwinkle.Tx) {
if o.Subscriptions != nil {
var oldSubscriptions []Subscription
db.Model(o).Related(&oldSubscriptions)
for _, oldsub := range oldSubscriptions {
match := false
for _, newsub := range o.Subscriptions {
if newsub.AddressID == oldsub.AddressID {
match = true
break
}
}
if !match {
var o UserAddress
db.First(&o, "id = ?", oldsub.AddressID)
if o.Medium != "noop" && o.Medium != "admin" {
if err := db.Where("address_id = ? AND group_id = ?", oldsub.AddressID, oldsub.GroupID).Delete(Subscription{}).Error; err != nil {
dbError(err)
}
}
}
}
}
if err := db.Save(o).Error; err != nil {
dbError(err)
}
}
示例2: Save
func (usr *User) Save(db *periwinkle.Tx) {
usr.ID = strings.ToLower(usr.ID)
if usr.Addresses != nil {
var oldAddresses []UserAddress
db.Model(usr).Related(&oldAddresses)
deleteAddressIDs := []int64{}
for o := range oldAddresses {
oldAddr := &oldAddresses[o]
match := false
for n := range usr.Addresses {
newAddr := &usr.Addresses[n]
if newAddr.Medium == oldAddr.Medium && newAddr.Address == oldAddr.Address {
newAddr.ID = oldAddr.ID
match = true
}
}
if !match && oldAddr.Medium != "noop" && oldAddr.Medium != "admin" {
deleteAddressIDs = append(deleteAddressIDs, oldAddr.ID)
}
}
if err := db.Save(usr).Error; err != nil {
dbError(err)
}
if len(deleteAddressIDs) > 0 {
if err := db.Where("id IN (?)", deleteAddressIDs).Delete(UserAddress{}).Error; err != nil {
dbError(err)
}
}
} else {
if err := db.Save(usr).Error; err != nil {
dbError(err)
}
}
}
示例3: Save
func (o *ShortURL) Save(db *periwinkle.Tx) {
if err := db.Save(o).Error; err != nil {
dbError(err)
}
}
示例4: Save
func (o *TwilioSMSMessage) Save(db *periwinkle.Tx) {
if err := db.Save(o).Error; err != nil {
dbError(err)
}
}
示例5: Save
func (o *Captcha) Save(db *periwinkle.Tx) {
if err := db.Save(o).Error; err != nil {
dbError(err)
}
}
示例6: Save
func (o *Session) Save(db *periwinkle.Tx) {
if err := db.Save(o).Error; err != nil {
dbError(err)
}
}