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: 15 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 User Repository using the provided logger

func (*Repository) ConfirmCredentialsToken

func (r *Repository) ConfirmCredentialsToken(ctx context.Context, tx pgx.Tx, req model.UserCredentialsRequest) error

ConfirmCredentialsToken updates the 'user_credentials' table to confirm user credentials based on the provided user ID. It sets the 'active' flag to true, updates the token and token type if provided, and sets the token expiration to NULL. The method can be used in a transaction (if a non-nil transaction context is provided) or as a standalone operation. If the transaction is successful, it confirms the user's credentials; otherwise, it returns an error.

func (*Repository) FindUser

func (r *Repository) FindUser(ctx context.Context, req *model.UserRequest) (*model.User, error)

FindUser searches for a user based on the provided UserRequest. It uses the SearchUsers method with a UsersRequest containing a single user ID. If a matching user is found, it returns the user details; otherwise, it returns pgx.ErrNoRows. In case of an inconsistency where more than one result is found, it returns an error.

func (*Repository) FindUserCredentials

func (r *Repository) FindUserCredentials(ctx context.Context, req model.UserCredentialsRequest) (model.UserCredentials, error)

FindUserCredentials retrieves user credentials from the 'user_credentials' table based on the specified request parameters. It supports querying by email, token, or user ID. The method constructs a SQL query dynamically based on the provided parameters, executes the query using the repository's connection pool, and returns the user credentials if found. If the query parameters are invalid or no matching credentials are found, an error is returned.

func (*Repository) InitRootUser

func (r *Repository) InitRootUser(ctx context.Context) error

func (*Repository) PatchUser

func (r *Repository) PatchUser(ctx context.Context, tx pgx.Tx, userId int32, param string, val any) error

func (*Repository) PerformUsersRequestQuery

func (r *Repository) PerformUsersRequestQuery(req *model.UsersRequest) []string

PerformUsersRequestQuery constructs a list of SQL query conditions based on the provided UsersRequest. It checks various filtering criteria, such as user IDs, names, emails, and creation timestamps, and creates corresponding SQL conditions for each valid criterion. The resulting list of conditions is intended to be used in a WHERE clause when querying user data. The sanitized strings are used to prevent SQL injection. The method returns a slice of strings representing the SQL conditions.

func (*Repository) PoolClose

func (r *Repository) PoolClose()

func (*Repository) ResetPassword

func (r *Repository) ResetPassword(ctx context.Context, req *model.UserCredentials) error

ResetPassword updates the 'user_credentials' table to reset a user's password based on the provided user credentials. It sets the 'active' flag to false, updates the token, token type, and token expiration based on the provided credentials. The method is designed to be used when a user requests a password reset.

func (*Repository) SearchUsers

func (r *Repository) SearchUsers(ctx context.Context, req *model.UsersRequest) ([]*model.User, error)

SearchUsers performs a search for users based on the provided UsersRequest. It constructs a dynamic SQL query using the parameters from the UsersRequest. The query is customized based on the filtering criteria such as user IDs, flags, and limits. If an error occurs during the query execution, it is logged along with the SQL query. The method returns a slice of User pointers representing the search results.

func (*Repository) TxCreateUser

func (r *Repository) TxCreateUser(ctx context.Context, tx pgx.Tx, u model.User) (int32, error)

TxCreateUser creates a new user in the 'users' table. If the transaction (tx) is provided, it executes the query within the transaction; otherwise, it uses the repository's connection pool to execute the query. The user's role (claim) is optional and can be nil if not specified. The method returns the newly created user's ID and an error, if any.

func (*Repository) TxNewAuthCredentials

func (r *Repository) TxNewAuthCredentials(ctx context.Context, tx pgx.Tx, uc model.UserCredentials) error

TxNewAuthCredentials creates new authentication credentials for a user in the 'user_credentials' table. If the transaction (tx) is provided, it executes the query within the transaction; otherwise, it uses the repository's connection pool to execute the query. The method returns an error if the database operation encounters any issues.

func (*Repository) UpdatePassword

func (r *Repository) UpdatePassword(ctx context.Context, tx pgx.Tx, req model.UserCredentials) error

UpdatePassword updates the password-related fields of a user in the 'user_credentials' table. It is typically used when a user changes their password. The method takes a user's credentials, including the user ID, the new hashed password, and the salt used for hashing. The update is performed within a transaction (if provided).

Jump to

Keyboard shortcuts

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