db

package
v0.0.0-...-8be21fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func InitDB

func InitDB() error

Types

type Action

type Action struct {
	ID           uint `gorm:"primaryKey;autoIncrement"`
	Name         string
	BetHistories []*BetHistory `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type BetHistory

type BetHistory struct {
	ID uint `gorm:"primaryKey;autoIncrement"`
	// Bet history belongs to table, user, action (with the amount)
	TableID  uint
	Table    Table `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UserID   uint
	User     User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	ActionID uint
	Action   Action `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	Amount   int
	Round    int
}

type Card

type Card struct {
	ID     uint `gorm:"primaryKey;autoIncrement"`
	Number uint
	Suit   Suit
	Image  string
	// table has common cards
	Tables                  []*Table                  `gorm:"many2many:table_cards;"`
	UsersTablesCards        []*UsersTablesCard        `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	CombinationDetailsCards []*CombinationDetailsCard `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type Combination

type Combination struct {
	ID                      uint `gorm:"primaryKey;autoIncrement"`
	Name                    string
	Score                   uint
	UsersTablesCombinations []*UsersTablesCombination `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type CombinationDetail

type CombinationDetail struct {
	ID                      uint                      `gorm:"primaryKey;autoIncrement"`
	CombinationDetailsCards []*CombinationDetailsCard `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type CombinationDetailsCard

type CombinationDetailsCard struct {
	CardID              uint
	Card                Card `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
	CombinationDetailID uint
	CombinationDetail   CombinationDetail `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
}

store list of cards that produce a specific combination

type Room

type Room struct {
	ID       uint `gorm:"primaryKey;autoIncrement"`
	Code     string
	Playing  bool
	Private  bool
	Password string
	// setup belongs to relation
	// 1 room has 1 user as owner
	UserID       uint
	User         User
	WaitingLists []*WaitingList `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type Suit

type Suit int
const (
	Diamond Suit = 0
	Heart   Suit = 1
	Club    Suit = 2
	Spade   Suit = 3
)

type Table

type Table struct {
	ID    uint `gorm:"primaryKey;autoIncrement"`
	Round int
	Done  bool
	Pot   int
	// table has current turn user
	UserID uint
	User   User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	// table belongs to one room
	RoomID uint
	Room   Room `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	// table has common cards
	Cards                   []*Card                   `gorm:"many2many:table_cards;"`
	BetHistories            []*BetHistory             `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UsersTablesCards        []*UsersTablesCard        `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UsersTablesCombinations []*UsersTablesCombination `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type User

type User struct {
	ID             uint `gorm:"primaryKey;autoIncrement"`
	Username       string
	HashedPassword string
	Money          int
	//WaitingLists     []*WaitingList     `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	BetHistories            []*BetHistory             `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UsersTablesCards        []*UsersTablesCard        `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UsersTablesCombinations []*UsersTablesCombination `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

type UsersTablesCard

type UsersTablesCard struct {
	TableID uint
	Table   Table `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
	UserID  uint
	User    User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
	CardID  uint
	Card    Card `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
}

store cards of user on specific table

type UsersTablesCombination

type UsersTablesCombination struct {
	TableID             uint
	Table               Table `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
	UserID              uint
	User                User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;primaryKey;"`
	CombinationID       uint
	Combination         Combination `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	CombinationDetailID uint
	CombinationDetail   CombinationDetail `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

store best combination of user on specific table

type WaitingList

type WaitingList struct {
	// when users join room, they will appear in wating list
	UserID         uint `gorm:"primaryKey"`
	RoomID         uint
	AvailableMoney int
	Ready          bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL