当前位置: 首页>>代码示例>>Golang>>正文


Golang periwinkle.Tx类代码示例

本文整理汇总了Golang中periwinkle.Tx的典型用法代码示例。如果您正苦于以下问题:Golang Tx类的具体用法?Golang Tx怎么用?Golang Tx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tx类的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: 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

示例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: 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

示例5: 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

示例6: NewGroup

func NewGroup(db *periwinkle.Tx, name string, existence []int, read []int, post []int, join []int) *Group {
	if name == "" {
		programmerError("Group name can't be empty")
	}
	name = strings.ToLower(name)
	subscriptions := make([]Subscription, 0)
	o := Group{
		ID:                 name,
		ReadPublic:         read[0],
		ReadConfirmed:      read[1],
		ExistencePublic:    existence[0],
		ExistenceConfirmed: existence[1],
		PostPublic:         post[0],
		PostConfirmed:      post[1],
		PostMember:         post[2],
		JoinPublic:         join[0],
		JoinConfirmed:      join[1],
		JoinMember:         join[2],
		Subscriptions:      subscriptions,
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:25,代码来源:group.go

示例7: GetAllGroups

func GetAllGroups(db *periwinkle.Tx) []Group {
	var o []Group
	if result := db.Find(&o); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:group.go

示例8: GetShortURLByID

func GetShortURLByID(db *periwinkle.Tx, id string) *ShortURL {
	var o ShortURL
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:shorturl.go

示例9: NewShortURL

func NewShortURL(db *periwinkle.Tx, u *url.URL) *ShortURL {
	o := ShortURL{
		ID:   RandomString(5),
		Dest: u.String(), // TODO: automatic marshalling
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:shorturl.go

示例10: GetTwilioSMSMessageBySID

func GetTwilioSMSMessageBySID(db *periwinkle.Tx, sid string) *TwilioSMSMessage {
	var o TwilioSMSMessage
	if result := db.First(&o, "message_s_id = ?", sid); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:twilio.go

示例11: GetCaptchaByID

func GetCaptchaByID(db *periwinkle.Tx, id string) *Captcha {
	var o Captcha
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:captcha.go

示例12: 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

示例13: dbSeed

func (o Medium) dbSeed(db *periwinkle.Tx) locale.Error {
	errs := errorList{}
	errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"email"}).Error))
	errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"sms"}).Error))
	errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"mms"}).Error))
	if len(errs) > 0 {
		return errs
	}
	return nil
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:medium.go

示例14: NewCaptcha

func NewCaptcha(db *periwinkle.Tx) *Captcha {
	o := Captcha{
		ID:    captcha.New(),
		Value: string(captcha.RandomDigits(defaultLen)),
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:captcha.go

示例15: GetMessageByID

func GetMessageByID(db *periwinkle.Tx, id string) *Message {
	var o Message
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
开发者ID:LukeShu,项目名称:periwinkle,代码行数:10,代码来源:message.go


注:本文中的periwinkle.Tx类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。