Started working on archive gamejam dbs

This commit is contained in:
Brian Buller 2017-10-02 08:44:55 -05:00
parent d398959dd9
commit f57d917297
2 changed files with 88 additions and 2 deletions

4
.gitignore vendored
View File

@ -7,5 +7,5 @@ gjvote.linuxarm
gjvote.win386.exe gjvote.win386.exe
gjvote.win64.exe gjvote.win64.exe
# Ignore the DB # Ignore the DBs
gjvote.db *.db

86
model_gamejam.go Normal file
View File

@ -0,0 +1,86 @@
package main
import (
"time"
"github.com/br0xen/boltease"
)
type Gamejam struct {
UUID string
Name string
Date time.Time
Teams []Team
Votes []Vote
db *boltease.DB
dbOpened int
}
// Archived Gamejam data is stored in it's own file to keep things nice and organized
func (gj *Gamejam) openDB() error {
gj.dbOpened += 1
if gj.dbOpened == 1 {
var err error
gj.db, err = boltease.Create(gj.UUID+".db", 0600, nil)
if err != nil {
return err
}
}
return nil
}
func (gj *Gamejam) closeDB() error {
gj.dbOpened -= 1
if gj.dbOpened == 0 {
return gj.db.CloseDB()
}
return nil
}
// archiveGameJam creates a separate gamejam file and populates it with the
// given name, teams, and votes
func archiveGamejam(nm string, teams []Team, votes []Vote) error {
// TODO
return nil
}
// dbGetGamejam returns a gamejam with the given uuid
// or nil if it couldn't be found
func dbGetGamejam(id string) *Gamejam {
var err error
if err = openDatabase(); err != nil {
return nil
}
defer closeDatabase()
ret := Gamejam{UUID: id}
// TODO: Load gamejam teams, other details
return ret
}
// dbGetGamejamByName looks for a gamejam with the given name
// and returns it, or it returns nil if it couldn't find it
func dbGetGamejamByName(nm string) *Gamejam {
var err error
if err = openDatabase(); err != nil {
return err
}
defer closeDatabase()
var gjid string
if gjs, err = db.GetBucketList([]string{"gamejams"}); err == nil {
for _, v := range gjUids {
tstNm, _ := db.GetValue([]string{"gamejams", v}, "name")
if tstNm == nm {
// We've got it
gjid = v
break
}
}
}
if gjid == "" {
return nil
}
return dbGetGamejam(gjid)
}