database

package
v0.0.0-...-1c441a6 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encrypt

func Encrypt(password string) (string, error)

Encrypt encrypts a string using bcrypt

Types

type AnswerDB

type AnswerDB struct {
	AnswerID   int    `json:"answer-id"`
	AnswerText string `json:"answer-text"`
}

type JWTClaimsDB

type JWTClaimsDB struct {
	Id        int    `json:"id"`
	UserId    int    `json:"user_id"`
	Timestamp int64  `json:"timestamp"`
	Token     string `json:"token"`
}

type Leadboard

type Leadboard struct {
	Nick      string `json:"nick"`
	UserImage string `json:"user-image"`
	Order     int    `json:"order"`
	Points    int    `json:"points"`
}

type MySQLDB

type MySQLDB struct {
	// contains filtered or unexported fields
}

Define a struct to hold the MySQL database connection.

func NewMySQLDB

func NewMySQLDB(username string, password string, host string, port int, database string) (*MySQLDB, error)

Create a function to establish a connection to the MySQL database.

func (*MySQLDB) AddToLobby

func (conn *MySQLDB) AddToLobby(userId int, lobbyType int) error

func (*MySQLDB) Close

func (db *MySQLDB) Close() error

Create a function to close the database connection.

func (*MySQLDB) GetAllRecords

func (db *MySQLDB) GetAllRecords(tableName string, where map[string]string) ([]map[string]interface{}, error)

Example: Fetch all records from a table.

func (*MySQLDB) InsertUserDB

func (conn *MySQLDB) InsertUserDB(username string, password string, nickname string) error

func (*MySQLDB) ParseResponseDB

func (conn *MySQLDB) ParseResponseDB(user_id int) (int, error)

func (*MySQLDB) QueryQuestionsDB

func (conn *MySQLDB) QueryQuestionsDB(limit int) ([]QuestionDB, error)

func (*MySQLDB) QueryUserDB

func (conn *MySQLDB) QueryUserDB(username string) (*UserDB, error)

func (*MySQLDB) RetrieveLeaderboard

func (conn *MySQLDB) RetrieveLeaderboard() ([]Leadboard, error)

type QuestionDB

type QuestionDB struct {
	QuestionID    int        `json:"question-id"`
	QuestionText  string     `json:"question-text"`
	CorrectAnswer int        `json:"correct-answer-id"`
	Points        int        `json:"point"`
	Answers       []AnswerDB `json:"answers"`
}

type UserDB

type UserDB struct {
	Id                int    `json:"id"`
	Username          string `json:"username"`
	Nick              string `json:"nick"`
	PasswordEncrypted string `json:"password_encrypted"`
	Image             string `json:"image"`
	QRcode            string `json:"qr_code"`
}

Jump to

Keyboard shortcuts

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