db

package
v0.0.0-...-98da78b Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InsertUserQuery     = "INSERT INTO users (name, email, password) VALUES (@userName, @userEmail, @hashedPassword);"
	GetUserByEmailQuery = "SELECT * FROM users WHERE email = @userEmail;"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InsertUser

type InsertUser struct {
	Name     string `json:"name"`
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,min=8"`
}

type Logger

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

func InitLogger

func InitLogger(logger *slog.Logger) *Logger

func (*Logger) Log

func (l *Logger) Log(ctx context.Context, level tracelog.LogLevel, msg string, data map[string]interface{})

type Postgres

type Postgres struct {
	User
	// contains filtered or unexported fields
}

func CreatePool

func CreatePool(ctx context.Context, conf config.Database, logger *slog.Logger) (*Postgres, error)

func (*Postgres) Close

func (p *Postgres) Close()

func (*Postgres) Conn

func (p *Postgres) Conn() *pgxpool.Pool

func (*Postgres) Ping

func (p *Postgres) Ping(ctx context.Context) error

type User

type User struct {
	Id        int       `json:"id"`
	Name      string    `json:"name"`
	Email     string    `json:"email"`
	Password  string    `json:"-"`
	Verified  bool      `json:"verified"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

exact order as in database

func (*User) GetByEmail

func (u *User) GetByEmail(ctx context.Context, email string) (User, error)

func (*User) InsertOne

func (u *User) InsertOne(ctx context.Context, user InsertUser) error

Jump to

Keyboard shortcuts

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