tableChessGames.go (1048B)
1 package database 2 3 import ( 4 "github.com/sirupsen/logrus" 5 "time" 6 ) 7 8 type ChessGame struct { 9 ID int64 10 UUID string 11 WhiteUserID UserID 12 BlackUserID UserID 13 PGN string 14 Outcome string 15 AccuracyWhite float64 16 AccuracyBlack float64 17 Stats []byte 18 CreatedAt time.Time 19 UpdatedAt time.Time 20 } 21 22 func (d *DkfDB) CreateChessGame(uuid string, whiteUserID, blackUserID UserID) (*ChessGame, error) { 23 chessGame := ChessGame{ 24 UUID: uuid, 25 WhiteUserID: whiteUserID, 26 BlackUserID: blackUserID, 27 Outcome: "*", 28 } 29 err := d.db.Create(&chessGame).Error 30 return &chessGame, err 31 } 32 33 func (d *DkfDB) GetChessGame(uuid string) (*ChessGame, error) { 34 out := ChessGame{} 35 err := d.db.First(&out, "uuid = ?", uuid).Error 36 return &out, err 37 } 38 39 // Save chessGame in the database 40 func (g *ChessGame) Save(db *DkfDB) error { 41 return db.db.Save(g).Error 42 } 43 44 // DoSave chessGame in the database, ignore error 45 func (g *ChessGame) DoSave(db *DkfDB) { 46 if err := g.Save(db); err != nil { 47 logrus.Error(err) 48 } 49 }