db

package
v0.0.0-...-693f06b Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(cfg Config, appName string) (*sqlx.DB, error)

Types

type Config

type Config struct {
	Host     string `env:"DB_HOST"`
	Port     int    `env:"DB_PORT"`
	User     string `env:"DB_USER"`
	Password string `env:"DB_PASSWORD"`
	DBName   string `env:"DB_NAME"`
	Schema   string `env:"DB_SCHEMA"`

	MaxIdleConns int    `env:"DB_MAX_IDLE_CONNS" envDefault:"2"`
	MaxOpenConns int    `env:"DB_MAX_OPEN_CONNS" envDefault:"4"`
	LogLevel     string `env:"DB_LOG_LEVEL" envDefault:"error"`
}

type User

type User struct {
	Id       int64  `db:"id"`
	Login    string `db:"login"`
	Email    string `db:"email"`
	Password string `db:"password"`
}

type UserRepo

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

func NewUserRepo

func NewUserRepo(db *sqlx.DB) UserRepo

func (UserRepo) GetById

func (u UserRepo) GetById(ctx context.Context, id int64) (User, error)

func (UserRepo) GetByLogin

func (u UserRepo) GetByLogin(ctx context.Context, login string) (User, error)

func (UserRepo) GetByLoginOrEmail

func (u UserRepo) GetByLoginOrEmail(ctx context.Context, login, email string) (User, error)

func (UserRepo) Insert

func (u UserRepo) Insert(ctx context.Context, user User) error

Jump to

Keyboard shortcuts

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