本文整理汇总了Golang中periwinkle.Tx.Where方法的典型用法代码示例。如果您正苦于以下问题:Golang Tx.Where方法的具体用法?Golang Tx.Where怎么用?Golang Tx.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类periwinkle.Tx
的用法示例。
在下文中一共展示了Tx.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetSubscriberIDs
func (grp *Group) GetSubscriberIDs(db *periwinkle.Tx) []string {
subscriptions := grp.GetSubscriptions(db)
addressIDs := make([]int64, len(subscriptions))
for i, sub := range subscriptions {
addressIDs[i] = sub.AddressID
}
var addresses []UserAddress
if len(addressIDs) > 0 {
if err := db.Where("id IN (?)", addressIDs).Find(&addresses).Error; err != nil {
dbError(err)
}
} else {
addresses = []UserAddress{}
}
userIDSet := map[string]bool{}
for _, address := range addresses {
userIDSet[address.UserID] = true
}
userIDs := make([]string, len(userIDSet))
i := 0
for userID := range userIDSet {
userIDs[i] = userID
i++
}
return userIDs
}
示例2: GetSubscriptions
func (addr *UserAddress) GetSubscriptions(db *periwinkle.Tx) []Subscription {
var subscriptions []Subscription
if err := db.Where("address_id = ?", addr.ID).Find(&subscriptions).Error; err != nil {
dbError(err)
}
return subscriptions
}
示例3: IsAdmin
func IsAdmin(db *periwinkle.Tx, userID string, group Group) bool {
subscriptions := group.GetSubscriptions(db)
addressIDs := make([]int64, len(subscriptions))
for i, subscription := range subscriptions {
addressIDs[i] = subscription.AddressID
}
var addresses []UserAddress
if len(addressIDs) > 0 {
if result := db.Where("id IN (?)", addressIDs).Find(&addresses); result.Error != nil {
if !result.RecordNotFound() {
panic("cant find any subscriptions corresponding user address")
}
}
} else {
// no subscriptions so user cannot possibly be subscribed
return false
}
for _, address := range addresses {
if address.UserID == userID && address.Medium == "admin" {
return true
}
}
// could not find user in subscribed user addresses, therefore, he/she isn't subscribed
return false
}
示例4: 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)
}
}
示例5: GetGroupsByMember
func GetGroupsByMember(db *periwinkle.Tx, user User) []Group {
subscriptions := user.GetSubscriptions(db)
var groupIDs []string
for _, sub := range subscriptions {
groupIDs = append(groupIDs, sub.GroupID)
}
var groups []Group
if len(groupIDs) > 0 {
if err := db.Where("id IN (?)", groupIDs).Find(&groups).Error; err != nil {
dbError(err)
}
} else {
groups = make([]Group, 0)
}
groupsByID := make(map[string]Group)
for _, group := range groups {
groupsByID[group.ID] = group
}
groupset := map[string]Group{}
for _, sub := range subscriptions {
// only add group if user is confirmed member or
// if group allows non confirmed members to see that it exists
if sub.Confirmed || groupsByID[sub.GroupID].ExistenceConfirmed == 2 {
groupset[sub.GroupID] = groupsByID[sub.GroupID]
}
}
var finalgroups []Group
for _, group := range groupset {
finalgroups = append(finalgroups, group)
}
return finalgroups
}
示例6: populate
func (u *User) populate(db *periwinkle.Tx) {
db.Where(`user_id = ?`, u.ID).Model(UserAddress{}).Find(&u.Addresses)
addressIDs := make([]int64, len(u.Addresses))
for i, address := range u.Addresses {
addressIDs[i] = address.ID
}
}
示例7: GetSubscriptions
func (grp *Group) GetSubscriptions(db *periwinkle.Tx) []Subscription {
var subscriptions []Subscription
if result := db.Where("group_id = ?", grp.ID).Find(&subscriptions); result.Error != nil {
if result.RecordNotFound() {
return []Subscription{}
}
dbError(result.Error)
}
return subscriptions
}
示例8: GetTwilioPoolByUserID
func GetTwilioPoolByUserID(db *periwinkle.Tx, userid string) []TwilioPool {
var o []TwilioPool
if result := db.Where("user_id = ?", userid).Find(&o); result.Error != nil {
if result.RecordNotFound() {
return nil
}
dbError(result.Error)
}
return o
}
示例9: GetAddressesByUserAndMedium
func GetAddressesByUserAndMedium(db *periwinkle.Tx, userID string, medium string) []UserAddress {
userID = strings.ToLower(userID)
var o []UserAddress
if result := db.Where("user_id=? AND medium=?", userID, medium).Find(&o); result.Error != nil {
if result.RecordNotFound() {
return nil
}
dbError(result.Error)
}
return o
}
示例10: GetTwilioNumberByID
func GetTwilioNumberByID(db *periwinkle.Tx, id int64) *TwilioNumber {
var twilio_num TwilioNumber
if result := db.Where("id = ?", id).First(&twilio_num); result.Error != nil {
if result.RecordNotFound() {
return nil
}
dbError(result.Error)
}
return &twilio_num
}
示例11: GetFrontEndSubscriptions
func (u *User) GetFrontEndSubscriptions(db *periwinkle.Tx) []Subscription {
var addresses []UserAddress
db.Where(`user_id = ? AND medium != "noop" AND medium != "admin"`, u.ID).Model(UserAddress{}).Find(&addresses)
addressIDs := make([]int64, len(u.Addresses))
for i, address := range addresses {
addressIDs[i] = address.ID
}
var subscriptions []Subscription
if len(addressIDs) > 0 {
if result := db.Where("address_id IN (?)", addressIDs).Find(&subscriptions); result.Error != nil {
if !result.RecordNotFound() {
dbError(result.Error)
}
}
} else {
subscriptions = make([]Subscription, 0)
}
return subscriptions
}
示例12: GetTwilioNumberByUserAndGroup
func GetTwilioNumberByUserAndGroup(db *periwinkle.Tx, userid string, groupid string) string {
var o TwilioPool
if result := db.Where(&TwilioPool{UserID: userid, GroupID: groupid}).First(&o); result.Error != nil {
if result.RecordNotFound() {
return ""
}
dbError(result.Error)
}
var twilioNum TwilioNumber
if result := db.Where("id = ?", o.NumberID).First(&twilioNum); result.Error != nil {
if result.RecordNotFound() {
return ""
}
dbError(result.Error)
}
return twilioNum.Number
}
示例13: DeleteUnusedTwilioNumber
func DeleteUnusedTwilioNumber(db *periwinkle.Tx, num string) locale.Error {
var twilioNum TwilioNumber
if result := db.Where("number = ?", num).First(&twilioNum); result.Error != nil {
if result.RecordNotFound() {
periwinkle.Logf("The number is already deleted!!!")
return nil
}
dbError(result.Error)
return locale.UntranslatedError(result.Error)
}
var twilioPool TwilioPool
result := db.Where("number_id = ?", twilioNum.ID).First(&twilioPool)
if result.Error != nil {
if result.RecordNotFound() {
o := db.Where("number = ?", num).Delete(&TwilioNumber{})
if o.Error != nil {
dbError(o.Error)
return locale.UntranslatedError(o.Error)
}
periwinkle.Logf("The number is deleted")
return nil
}
dbError(result.Error)
return locale.UntranslatedError(result.Error)
}
periwinkle.Logf("The number is used for a twilio pool")
return nil
}
示例14: GetGroupByUserAndTwilioNumber
func GetGroupByUserAndTwilioNumber(db *periwinkle.Tx, userid string, twilioNum string) *Group {
var num TwilioNumber
if result := db.Where("number = ?", twilioNum).First(&num); result.Error != nil {
if result.RecordNotFound() {
return nil
}
dbError(result.Error)
}
var o TwilioPool
if result := db.Where(&TwilioPool{UserID: userid, NumberID: num.ID}).First(&o); result.Error != nil {
if result.RecordNotFound() {
return nil
}
dbError(result.Error)
}
var group Group
if result := db.Where("id = ?", o.GroupID).First(&group); result.Error != nil {
if result.RecordNotFound() {
return nil
}
dbError(result.Error)
}
return &group
}
示例15: GetPublicAndSubscribedGroups
func GetPublicAndSubscribedGroups(db *periwinkle.Tx, user User) []Group {
groups := GetGroupsByMember(db, user)
// also get public groups
var publicgroups []Group
if result := db.Where(&Group{ExistencePublic: 1}).Find(&publicgroups); result.Error != nil {
if !result.RecordNotFound() {
dbError(result.Error)
}
}
// merge public groups and subscribed groups
for _, publicgroup := range publicgroups {
for _, group := range groups {
if group.ID == publicgroup.ID {
break
}
}
groups = append(groups, publicgroup)
}
// return them
return groups
}