psql

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository struct {
	pgxs.PickfighterRepo
}

Repository represents a repository for interacting with user data in the database. It embeds the pgxs.Repo, which provides the basic PostgreSQL database operations.

func New

func New(ctx context.Context) (*Repository, error)

New creates and returns a new instance of Repository using the provided logger

func (*Repository) CreateFightResult

func (r *Repository) CreateFightResult(ctx context.Context, tx pgx.Tx, req *eventmodel.FightResultRequest) error

CreateFightResult creates result row in fight_results table. It takes a context, a transaction, and a FightResultRequest. It returns an error if the update fails.

func (*Repository) GetEventId

func (r *Repository) GetEventId(ctx context.Context, tx pgx.Tx, fightId int32) (int32, error)

GetEventId retrieves the event ID associated with a specific fight from the fights table. It takes a transaction (tx), the fight ID, and returns the corresponding event ID. If the query is successful, it returns the event ID; otherwise, it returns -1 and the encountered error.

func (*Repository) GetUndoneFightsCount

func (r *Repository) GetUndoneFightsCount(ctx context.Context, tx pgx.Tx, eventId int32) (int, error)

GetUndoneFightsCount retrieves the count of undone fights for a specific event from the fights table. It takes a transaction (tx), the event ID, and returns the number of fights that are not marked as done (is_done = false). If the query is successful, it returns the count, otherwise, it returns an error.

func (*Repository) PoolClose

func (r *Repository) PoolClose()

func (*Repository) SearchBets

func (r *Repository) SearchBets(ctx context.Context, userId int32) ([]*eventmodel.Bet, error)

SearchBets retrieves a list of bets for a given user ID from the 'bets' table. It takes a context and a user ID, and returns a slice of Bet models or an error if the query fails.

func (*Repository) SearchBetsCount

func (r *Repository) SearchBetsCount(ctx context.Context, userId int32) (int32, error)

SearchBetsCount retrieves the count of bets for a given user ID from the 'bets' table. It takes a context and a user ID, and returns the count of bets or an error if the query fails.

func (*Repository) SearchEvents

func (r *Repository) SearchEvents(ctx context.Context) ([]*eventmodel.Event, error)

SearchEvents retrieves a list of events along with associated fights and fighter information. It uses Common Table Expressions (CTE) to rank events and filter them based on whether they are done or not. The method takes a context, retrieves a limited number of events (specified by the 'limit' parameter), and returns a slice of FullEventResponse containing event details, associated fights, and fighter information. If there is an error during the database query, it returns nil and the encountered error.

func (*Repository) SearchEventsCount

func (r *Repository) SearchEventsCount(ctx context.Context) (int32, error)

SearchEventsCount returns the count of events in the system, considering the limit constraint.

func (*Repository) SetEventDone

func (r *Repository) SetEventDone(ctx context.Context, tx pgx.Tx, eventId int32) error

SetEventDone updates the 'is_done' field of an event in the events table. It takes a transaction (tx) and the event ID as parameters and sets the 'is_done' column to true for the specified event. If the update is successful, it returns nil. In case of an error during the update, it returns the error details.

func (*Repository) SetFightIsDone

func (r *Repository) SetFightIsDone(ctx context.Context, tx pgx.Tx, fightId int) error

SetFightResult set is_done field as true of a fight in the 'fights' table. It takes a context, a transaction, and a fight id. It returns an error if the update fails.

func (*Repository) TxCreateBet

func (r *Repository) TxCreateBet(ctx context.Context, tx pgx.Tx, bet *eventmodel.Bet) (int32, error)

CreateBet inserts a new bet into the 'bets' table. It takes a context, a Bet model and returns the newly created bet's ID or an error if the insertion fails.

func (*Repository) TxCreateEvent

func (r *Repository) TxCreateEvent(ctx context.Context, tx pgx.Tx, e *eventmodel.EventRequest) (int32, error)

TxCreateEvent creates a new event in the 'events' table and returns the event ID. It uses a transaction (tx) if provided, otherwise, it uses the repository's connection pool.

func (*Repository) TxCreateEventFight

func (r *Repository) TxCreateEventFight(ctx context.Context, tx pgx.Tx, f eventmodel.Fight) error

TxCreateEventFight creates a new fight in the 'fights' table within a transaction. It takes a context, a transaction, and a Fight model. It returns an error if the insertion fails.

Jump to

Keyboard shortcuts

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