database

package
v0.0.0-...-f80fce7 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INACTIVE              = 0
	UNREGISTERED          = 1
	REGISTERED            = 2
	MEMBER                = 3
	OFFICER               = 4 // OP
	ADMIN                 = 5
	OWNER        UserRole = 6
)

Definitions of UserRole Values - OWNER being the highest, INACTIVE being the lowest

Variables

This section is empty.

Functions

func CloseDB

func CloseDB() error

CloseDB - Close Database Connection

func ConnectToDB

func ConnectToDB(dbType DBType, databaseURI string) error

ConnectToDB - Initialize and Start Database Connection

func DeleteGame

func DeleteGame(game Game) error

DeleteGame - Delete a game.

func DeleteMessage

func DeleteMessage(message Message) error

DeleteMessage - Delete a message.

func DeleteUser

func DeleteUser(user User) error

DeleteUser - Delete a user.

func InsertGame

func InsertGame(game Game) error

InsertGame - Add a game.

func InsertGameUserAssoc

func InsertGameUserAssoc(game Game, user User) error

InsertGameUserAssoc - insert an association in the table between the game and the user passed in

func InsertMessage

func InsertMessage(message Message) error

InsertMessage - Add a message.

func InsertUser

func InsertUser(user User) error

InsertUser - Add a user.

func InsertUserMessageAssoc

func InsertUserMessageAssoc(message Message, user User) error

InsertUserMessageAssoc - insert an association in the table between the message and the user passed in

func IsInGameDB

func IsInGameDB(game Game) (bool, error)

IsInGameDB - checks if a game exists in the database

func IsInMsgDB

func IsInMsgDB(msg Message) (bool, error)

IsInMsgDB - checks if a message exists in the database

func IsInUserDB

func IsInUserDB(user User) (bool, error)

IsInUserDB - checks if a user exists in the database

func UpdateGame

func UpdateGame(game Game) error

UpdateGame - Update a Game (if it exists)

func UpdateMessage

func UpdateMessage(message Message) error

UpdateMessage - Update a Message (if it exists?)

func UpdateUser

func UpdateUser(user User) error

UpdateUser - Update a User (if it exists)

Types

type DBType

type DBType uint8

DBType - enum for database types supported out-of-the-box by gorm

const (
	SQLITE DBType = iota
	MYSQL
	MARIADB
	POSTGRESQL
	SQLSERVER
)

Definition of DBType Enum

type Game

type Game struct {
	ID         uint64 `gorm:"PRIMARY_KEY"`
	Name       string `gorm:"UNIQUE;NOT NULL"`
	MaxPlayers uint8
	Owners     []User `gorm:"many2many:GameUser;"`
}

Game - represents a game in the database

func SelectGame

func SelectGame(game Game) (Game, error)

SelectGame - return a game Object in the database

func SelectGamesForPlayerCount

func SelectGamesForPlayerCount(PlayerCount uint8) ([]Game, error)

SelectGamesForPlayerCount - Select the games objects that have at least the player count indicated

type Message

type Message struct {
	ID             uint64 `gorm:"PRIMARY_KEY"`
	DateFirstSent  time.Time
	MessageContent string `gorm:"UNIQUE;NOT NULL"`
	Senders        []User `gorm:"many2many:MessageUser;"`
}

Message - represents a message in the database

func SelectMessage

func SelectMessage(msg Message) (Message, error)

SelectMessage - return a Message Object in the database

type User

type User struct {
	ID        uint64    `gorm:"PRIMARY_KEY"`
	DiscordID string    `gorm:"UNIQUE;NOT NULL"`
	Username  string    `gorm:"NOT NULL"`
	Nickname  string    `gorm:"NOT NULL"`
	RealName  string    `gorm:"NOT NULL"`
	Role      UserRole  `gorm:"DEFAULT:0"`
	Games     []Game    `gorm:"many2many:GameUser;"`
	Messages  []Message `gorm:"many2many:MessageUser;"`
}

User - represents a user in the database

func SelectUser

func SelectUser(user User) (User, error)

SelectUser - return a User Object in the database by the primary key, discordID

func SelectUserByNickname

func SelectUserByNickname(nickname string) (User, error)

SelectUserByNickname - select the first user that has the nickname indicated

func SelectUserByUsername

func SelectUserByUsername(username string) (User, error)

SelectUserByUsername - select the first user that has the username indicated

type UserRole

type UserRole uint8

UserRole enum - represents permissions levels

Jump to

Keyboard shortcuts

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