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


Golang kol.DB类代码示例

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


在下文中一共展示了DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Updated

func (self *Message) Updated(d *kol.DB, old *Message) {
	g := Game{Id: self.GameId}
	if err := d.Get(&g); err != nil {
		panic(err)
	}
	d.EmitUpdate(&g)
}
开发者ID:JorenC,项目名称:diplicity,代码行数:7,代码来源:message.go

示例2: Disallows

func (self Members) Disallows(d *kol.DB, asking *user.User) (result bool, err error) {
	var askerList map[string]bool
	if askerList, err = asking.Blacklistings(d); err != nil {
		return
	}
	for _, member := range self {
		if askerList[member.UserId.String()] {
			result = true
			return
		}
	}
	for _, member := range self {
		memberUser := &user.User{Id: member.UserId}
		if err = d.Get(memberUser); err != nil {
			return
		}
		var memberList map[string]bool
		if memberList, err = memberUser.Blacklistings(d); err != nil {
			return
		}
		if memberList[asking.Id.String()] {
			result = true
			return
		}
	}
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:27,代码来源:member.go

示例3: Created

func (self *Member) Created(d *kol.DB) {
	g := Game{Id: self.GameId}
	if err := d.Get(&g); err != nil {
		panic(err)
	}
	d.EmitUpdate(&g)
}
开发者ID:arlm,项目名称:diplicity,代码行数:7,代码来源:member.go

示例4: Messages

func (self *Game) Messages(d *kol.DB) (result Messages, err error) {
	if err = d.Query().Where(kol.Equals{"GameId", self.Id}).All(&result); err != nil {
		return
	}
	sort.Sort(result)
	return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:7,代码来源:game.go

示例5: Deleted

func (self *Member) Deleted(d *kol.DB) {
	g := Game{Id: self.GameId}
	if err := d.Get(&g); err == nil {
		d.EmitUpdate(&g)
	} else if err != kol.NotFound {
		panic(err)
	}
}
开发者ID:arlm,项目名称:diplicity,代码行数:8,代码来源:member.go

示例6: Member

func (self *Game) Member(d *kol.DB, email string) (result *Member, err error) {
	var member Member
	var found bool
	if found, err = d.Query().Where(kol.And{kol.Equals{"GameId", self.Id}, kol.Equals{"UserId", kol.Id(email)}}).First(&member); found && err == nil {
		result = &member
	}
	return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:8,代码来源:game.go

示例7: Set

func Set(d *kol.DB, at time.Duration) (err error) {
	epoch := &Epoch{
		Id: kol.Id(epochKey),
		At: at,
	}
	err = d.Set(epoch)
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:8,代码来源:epoch.go

示例8: Updated

func (self *Member) Updated(d *kol.DB, old *Member) {
	if old != self {
		g := Game{Id: self.GameId}
		if err := d.Get(&g); err != nil {
			panic(err)
		}
		d.EmitUpdate(&g)
	}
}
开发者ID:arlm,项目名称:diplicity,代码行数:9,代码来源:member.go

示例9: Updated

func (self *Game) Updated(d *kol.DB, old *Game) {
	if old != self {
		members, err := self.Members(d)
		if err == nil {
			for _, member := range members {
				d.EmitUpdate(&member)
			}
		}
	}
}
开发者ID:JorenC,项目名称:diplicity,代码行数:10,代码来源:game.go

示例10: Get

func Get(d *kol.DB) (result time.Duration, err error) {
	epoch := &Epoch{
		Id: kol.Id(epochKey),
	}
	if err = d.Get(epoch); err != nil {
		if err == kol.NotFound {
			err = nil
		} else {
			return
		}
	}
	result = epoch.At + time.Now().Sub(time.Unix(0, atomic.LoadInt64(&deltaPoint)))
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:14,代码来源:epoch.go

示例11: ReliabilityDelta

func (self *Member) ReliabilityDelta(d *kol.DB, i int) (err error) {
	user := &user.User{Id: self.UserId}
	if err = d.Get(user); err != nil {
		return
	}
	if i > 0 {
		user.HeldDeadlines += i
	} else {
		user.MissedDeadlines -= i
	}
	if err = d.Set(user); err != nil {
		return
	}
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:15,代码来源:member.go

示例12: Users

func (self *Game) Users(d *kol.DB) (result user.Users, err error) {
	members, err := self.Members(d)
	if err != nil {
		return
	}
	result = make(user.Users, len(members))
	for index, member := range members {
		user := user.User{Id: member.UserId}
		if err = d.Get(&user); err != nil {
			return
		}
		result[index] = user
	}
	return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:15,代码来源:game.go

示例13: ToState

func (self *Member) ToState(d *kol.DB, g *Game, email string, isMember bool, isAdmin bool) (result *MemberState, err error) {
	result = &MemberState{
		Member: &Member{
			Id: self.Id,
		},
		User: &user.User{},
	}
	secretNation := false
	secretEmail := false
	secretNickname := false
	var flag common.SecretFlag
	switch g.State {
	case common.GameStateCreated:
		flag = common.SecretBeforeGame
	case common.GameStateStarted:
		flag = common.SecretDuringGame
	case common.GameStateEnded:
		flag = common.SecretAfterGame
	default:
		panic(fmt.Errorf("Unknown game state for %+v", g))
	}
	secretNation, secretEmail, secretNickname = g.SecretNation&flag == flag, g.SecretEmail&flag == flag, g.SecretNickname&flag == flag
	isMe := string(self.UserId) == email
	if isAdmin || isMe || !secretNation {
		result.Member.Nation = self.Nation
	}
	if isAdmin || isMe || !secretEmail || !secretNickname {
		foundUser := &user.User{Id: self.UserId}
		if err = d.Get(foundUser); err != nil {
			return
		}
		if isAdmin || (isMember && (isMe || !secretEmail)) {
			result.User.Email = foundUser.Email
		}
		if isAdmin || (isMe || !secretNickname) {
			result.User.Nickname = foundUser.Nickname
		}
		if isAdmin || isMe {
			result.Member.Committed = self.Committed
			result.Member.Options = self.Options
			result.Member.NoOrders = self.NoOrders
		}
	}
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:45,代码来源:member.go

示例14: allocate

func (self *Game) allocate(d *kol.DB, phase *Phase) (err error) {
	members, err := self.Members(d)
	if err != nil {
		return
	}
	switch self.AllocationMethod {
	case common.RandomString:
		for memberIndex, nationIndex := range rand.Perm(len(members)) {
			members[memberIndex].Nation = common.VariantMap[self.Variant].Nations[nationIndex]
		}
	case common.PreferencesString:
		prefs := make([][]dip.Nation, len(members))
		for index, member := range members {
			prefs[index] = member.PreferredNations
		}
		for index, nation := range optimizePreferences(prefs) {
			members[index].Nation = nation
		}
	default:
		return fmt.Errorf("Unknown allocation method %v", self.AllocationMethod)
	}
	for index, _ := range members {
		opts := dip.Options{}
		if opts, err = phase.Options(members[index].Nation); err != nil {
			return
		}
		members[index].Options = opts
		if len(opts) == 0 {
			members[index].Committed = true
			members[index].NoOrders = true
		} else {
			members[index].Committed = false
			members[index].NoOrders = false
		}
		if err = d.Set(&members[index]); err != nil {
			return
		}
	}
	return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:40,代码来源:game.go

示例15: Phases

func (self *Game) Phases(d *kol.DB) (result Phases, err error) {
	err = d.Query().Where(kol.Equals{"GameId", self.Id}).All(&result)
	return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:4,代码来源:game.go


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