db

package
v0.0.0-...-42bc384 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DbPool

func DbPool(ctx context.Context, maxConnection int32, logger tracelog.Logger, logLevel string) (*pgxpool.Pool, error)

NOTE: tracing support for tracelog(pgx)

https://github.com/jackc/pgx/discussions/1677#discussioncomment-8815982

NOTE: TraceLog doesn't take logLevel as we have in our logging library it

	 takes in a number, we will need to add a mapping fucntion, for now
 	 we're just keeping the argument for nothing but its OK

Types

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type Flag

type Flag struct {
	ID           string           `json:"id"`
	Question     string           `json:"question"`
	Answer       string           `json:"answer"`
	AnswerOption []byte           `json:"answer_option"`
	Score        int32            `json:"score"`
	SeqNum       int32            `json:"seq_num"`
	Correct      *bool            `json:"correct"`
	TeamID       *string          `json:"team_id"`
	CreatedAt    pgtype.Timestamp `json:"created_at"`
	UpdatedAt    pgtype.Timestamp `json:"updated_at"`
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AssignQuestionToTeam

func (q *Queries) AssignQuestionToTeam(ctx context.Context, teamID *string) error

AssignQuestionToTeam

WITH to_update AS (
    SELECT
        id
    FROM
        flag
    WHERE
        team_id IS NULL
    LIMIT 5)
UPDATE
    flag
SET
    team_id = $1
WHERE
    id IN (
        SELECT
            id
        FROM
            to_update)

func (*Queries) CheckIfAnswered

func (q *Queries) CheckIfAnswered(ctx context.Context, id string) (bool, error)

CheckIfAnswered

SELECT
    CASE WHEN correct IS NOT NULL
        AND id = $1 THEN
        TRUE
    ELSE
        FALSE
    END
FROM
    flag
WHERE
    id = $1

func (*Queries) GetFlag

func (q *Queries) GetFlag(ctx context.Context, id string) (Flag, error)

GetFlag

SELECT
    id, question, answer, answer_option, score, seq_num, correct, team_id, created_at, updated_at
FROM
    flag
WHERE
    id = $1

func (*Queries) GetTeam

func (q *Queries) GetTeam(ctx context.Context) (Team, error)

GetTeam

SELECT
    id, team_name, secret, map_url
FROM
    team
LIMIT 1

func (*Queries) GetTeamBySecret

func (q *Queries) GetTeamBySecret(ctx context.Context, secret string) (Team, error)

GetTeamBySecret

SELECT
    id, team_name, secret, map_url
FROM
    team
WHERE
    secret = $1

func (*Queries) MarkFlagAsCorrect

func (q *Queries) MarkFlagAsCorrect(ctx context.Context, id string) error

MarkFlagAsCorrect

UPDATE
    flag
SET
    correct = TRUE
WHERE
    id = $1

func (*Queries) MarkFlagAsIncorrect

func (q *Queries) MarkFlagAsIncorrect(ctx context.Context, id string) error

MarkFlagAsIncorrect

UPDATE
    flag
SET
    correct = FALSE
WHERE
    id = $1

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type Team

type Team struct {
	ID       string `json:"id"`
	TeamName string `json:"team_name"`
	Secret   string `json:"secret"`
	MapUrl   string `json:"map_url"`
}

Jump to

Keyboard shortcuts

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