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: 6 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 fighter-related data in the database. It embeds the pgxs.Repo, which provides the basic PostgreSQL database operations.

func New

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

New creates and returns a new instance of Fighters Repository

func (*Repository) CreateNewFighter

func (r *Repository) CreateNewFighter(ctx context.Context, tx pgx.Tx, fighter model.Fighter) (int32, error)

CreateNewFighter creates a new entry for a fighter in the database. It takes a context, a database transaction (tx), and a model.Fighter struct containing the fighter's data. The method constructs and executes a SQL query to insert the provided fighter data into the 'fighters.fighters' table. If a transaction (tx) is provided, the insertion is performed within that transaction; otherwise, it is executed as a standalone query. The method returns the ID of the newly created fighter and an error if the insertion operation encounters any issues.

func (*Repository) CreateNewFighterStats

func (r *Repository) CreateNewFighterStats(ctx context.Context, tx pgx.Tx, stats model.FighterStats) error

CreateNewFighterStats creates a new entry for fighter statistics in the database. It takes a context, a database transaction (tx), and a model.FighterStats struct containing the statistics data. The method constructs and executes a SQL query to insert the provided statistics into the 'fighters.fighter_stats' table. If a transaction (tx) is provided, the insertion is performed within that transaction; otherwise, it is executed as a standalone query. The method returns an error if the insertion operation encounters any issues.

func (*Repository) FindFighter

func (r *Repository) FindFighter(ctx context.Context, req model.Fighter) (int32, error)

FindFighter searches for a fighter in the database based on the provided model.Fighter struct. It takes a context, a model.Fighter struct containing the search criteria (name and debut timestamp). The method constructs and executes a SQL query to select the fighter_id from the 'fighters' table where the name and debut_timestamp match the provided criteria. The result is scanned into the fighterId variable. If a matching fighter is found, the method returns the fighter_id; otherwise, it returns an error indicating that no matching fighter was found.

func (*Repository) PoolClose

func (r *Repository) PoolClose()

func (*Repository) SearchFighters

func (r *Repository) SearchFighters(ctx context.Context, req *model.FightersRequest) ([]*model.Fighter, error)

SearchFighters retrieves a list of fighters based on the provided FightersRequest. It constructs a SQL query to join the fighters and fighter_stats tables and applies optional conditions specified in the FightersRequest for filtering. The result includes information about the fighters and their statistics. If the request is successful, it returns a slice of Fighter models. In case of an error, it returns nil and the error details.

func (*Repository) SearchFightersCount

func (r *Repository) SearchFightersCount(ctx context.Context, req *model.FightersRequest) (int32, error)

SearchFightersCount retrieves the count of fighters based on the provided FightersRequest. It constructs a SQL query to count the number of records in the fighters table, applying optional conditions specified in the FightersRequest for filtering. If the request is successful, it returns the count of fighters. In case of an error, it returns 0 and the error details.

func (*Repository) UpdateFighter

func (r *Repository) UpdateFighter(ctx context.Context, tx pgx.Tx, fighter model.Fighter) (int32, error)

UpdateFighter updates the information of a fighter in the database. It takes a context, a database transaction (tx), and a model.Fighter struct containing the updated information. The method constructs and executes a SQL query to update the corresponding fields in the 'fighters.fighters' table based on the fighter's ID. The fighter ID is returned if the update is successful. If a transaction (tx) is provided, the update is performed within that transaction; otherwise, it is executed as a standalone query. The method returns the fighter ID and an error if the update operation encounters any issues.

func (*Repository) UpdateFighterStats

func (r *Repository) UpdateFighterStats(ctx context.Context, tx pgx.Tx, stats model.FighterStats) error

UpdateFighterStats updates the statistics of a fighter in the database. It takes a context, a database transaction (tx), and a model.FighterStats struct containing the updated statistics. The method constructs and executes a SQL query to update the corresponding fields in the 'fighters.fighter_stats' table based on the fighter's ID. If a transaction (tx) is provided, the update is performed within that transaction; otherwise, it is executed as a standalone query. The method returns an error if the update operation encounters any issues.

Jump to

Keyboard shortcuts

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