postgres

package
v0.0.0-...-7bf8d03 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Querier
	*pgxpool.Pool
}

DB wraps the Querier interface and a pgxpool.Pool instance.

func NewDB

func NewDB(ctx context.Context, cfg *config.DB) (*DB, error)

NewDB creates a new DB instance using the provided config.

func (*DB) ExecTX

func (d *DB) ExecTX(ctx context.Context, fn func(Querier) error) error

ExecTX wraps the provided function in a transaction and executes it.

func (*DB) Migrate

func (d *DB) Migrate(dialect string) error

Migrate runs the goose migration tool to apply new migrations.

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type InsertUserParams

type InsertUserParams struct {
	ID          uuid.UUID
	Email       string
	Password    string
	FullName    string
	PhoneNumber string
	Role        UserRole
	CreatedAt   pgtype.Timestamptz
	UpdatedAt   pgtype.Timestamptz
}

type NullUserRole

type NullUserRole struct {
	UserRole UserRole
	Valid    bool // Valid is true if UserRole is not NULL
}

func (*NullUserRole) Scan

func (ns *NullUserRole) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullUserRole) Value

func (ns NullUserRole) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Querier

type Querier interface {
	DeleteUser(ctx context.Context, id uuid.UUID) (uuid.UUID, error)
	InsertUser(ctx context.Context, arg InsertUserParams) error
	SelectAllUsers(ctx context.Context, arg SelectAllUsersParams) ([]User, error)
	SelectUserByEmail(ctx context.Context, email string) (User, error)
	SelectUserByID(ctx context.Context, id uuid.UUID) (User, error)
	UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) DeleteUser

func (q *Queries) DeleteUser(ctx context.Context, id uuid.UUID) (uuid.UUID, error)

func (*Queries) InsertUser

func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) error

func (*Queries) SelectAllUsers

func (q *Queries) SelectAllUsers(ctx context.Context, arg SelectAllUsersParams) ([]User, error)

func (*Queries) SelectUserByEmail

func (q *Queries) SelectUserByEmail(ctx context.Context, email string) (User, error)

func (*Queries) SelectUserByID

func (q *Queries) SelectUserByID(ctx context.Context, id uuid.UUID) (User, error)

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type SelectAllUsersParams

type SelectAllUsersParams struct {
	Limit  int32
	Offset int32
}

type Session

type Session struct {
	Token  string
	Data   []byte
	Expiry pgtype.Timestamptz
}

type UpdateUserParams

type UpdateUserParams struct {
	ID          uuid.UUID
	Email       pgtype.Text
	Password    pgtype.Text
	FullName    pgtype.Text
	PhoneNumber pgtype.Text
	Role        NullUserRole
}

type User

type User struct {
	ID          uuid.UUID
	Role        UserRole
	Email       string
	Password    string
	FullName    string
	PhoneNumber string
	CreatedAt   pgtype.Timestamptz
	UpdatedAt   pgtype.Timestamptz
}

type UserRole

type UserRole string
const (
	UserRoleAdmin    UserRole = "admin"
	UserRoleCustomer UserRole = "customer"
)

func (*UserRole) Scan

func (e *UserRole) Scan(src interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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