本文整理汇总了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)
}
示例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
}
示例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)
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}