postgres

package
v0.0.0-...-f767cfc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package postgres provides a PostgreSQL repository implementation for storing and managing users.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgreSQL

func NewPostgreSQL(ctx context.Context, config Config) (*sqlx.DB, error)

NewPostgreSQL creates a new PostgreSQL database connection using the provided configuration.

Types

type Config

type Config struct {
	Host     string // Host is the address of the PostgreSQL server.
	Port     string // Port is the port number to connect to on the PostgreSQL server.
	Username string // Username is the username used to authenticate against the PostgreSQL server.
	Password string // Password is the password used to authenticate against the PostgreSQL server.
	DBName   string // DBName is the name of the PostgreSQL database to connect to.
	SSLMode  string // SSLMode controls whether or with what priority a secure SSL TCP/IP connection will be negotiated with the PostgreSQL server.
}

Config stores the configuration information required to connect to a PostgreSQL database.

type UserRepository

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

UserRepository provides an implementation of the user repository for a PostgreSQL database.

func NewUserRepository

func NewUserRepository(db *sqlx.DB) (*UserRepository, error)

NewUserRepository creates a new instance of the UserRepository with the provided handle to the PostgreSQL database.

If db is nil, returns an error.

func (UserRepository) FindUserByUserID

func (r UserRepository) FindUserByUserID(ctx context.Context, userID string) (user domain.User, err error)

FindUserByUserID finds a user in the PostgreSQL database by their user ID.

If the user is not found, returns `user.ErrUserNotFound`.

func (UserRepository) FindUserByUsername

func (r UserRepository) FindUserByUsername(ctx context.Context, username string) (user domain.User, err error)

FindUserByUsername finds a user in the PostgreSQL database by their username.

If the user is not found, returns `user.ErrUserNotFound`.

func (UserRepository) SaveUser

func (r UserRepository) SaveUser(ctx context.Context, user domain.User) error

SaveUser saves a user to the PostgreSQL database.

If the user already exists, returns `user.ErrUserAlreadyExists`.

Jump to

Keyboard shortcuts

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