當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Tx.Where方法代碼示例

本文整理匯總了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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:26,代碼來源:group.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:7,代碼來源:user.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:25,代碼來源:subscription.go

示例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)
	}

}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:32,代碼來源:group.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:34,代碼來源:group.go

示例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
	}
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:7,代碼來源:user.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:10,代碼來源:group.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:11,代碼來源:twilio.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:11,代碼來源:user.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:13,代碼來源:twilio.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:19,代碼來源:user.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:20,代碼來源:twilio.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:30,代碼來源:twilio.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:31,代碼來源:twilio.go

示例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
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:22,代碼來源:group.go


注:本文中的periwinkle.Tx.Where方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。