postgres

package
v0.0.0-...-3ca1276 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID          uuid.UUID
	Role        AccountRole
	Email       string
	Password    string
	FullName    string
	PhoneNumber string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (Account) ToDomain

func (a Account) ToDomain() *user.Account

ToDomain converts generated Account struct to domain account struct

type AccountRole

type AccountRole string
const (
	AccountRoleAdmin    AccountRole = "admin"
	AccountRoleCustomer AccountRole = "customer"
)

func (*AccountRole) Scan

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

type DB

type DB struct {
	Querier
	*pgxpool.Pool
}

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

func Connect

func Connect(ctx context.Context, connURI string) (*DB, error)

Connect 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() 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 InsertAccountParams

type InsertAccountParams struct {
	ID          uuid.UUID
	Email       string
	Password    string
	FullName    string
	PhoneNumber string
	Role        AccountRole
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type NullAccountRole

type NullAccountRole struct {
	AccountRole AccountRole
	Valid       bool // Valid is true if AccountRole is not NULL
}

func (*NullAccountRole) Scan

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

Scan implements the Scanner interface.

func (NullAccountRole) Value

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

Value implements the driver Valuer interface.

type Querier

type Querier interface {
	DeleteAccount(ctx context.Context, id uuid.UUID) (int64, error)
	InsertAccount(ctx context.Context, arg InsertAccountParams) error
	SelectAccountByEmail(ctx context.Context, email string) (Account, error)
	SelectAccountByID(ctx context.Context, id uuid.UUID) (Account, error)
	SelectAllAccounts(ctx context.Context, arg SelectAllAccountsParams) ([]Account, error)
	UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) DeleteAccount

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

func (*Queries) InsertAccount

func (q *Queries) InsertAccount(ctx context.Context, arg InsertAccountParams) error

func (*Queries) SelectAccountByEmail

func (q *Queries) SelectAccountByEmail(ctx context.Context, email string) (Account, error)

func (*Queries) SelectAccountByID

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

func (*Queries) SelectAllAccounts

func (q *Queries) SelectAllAccounts(ctx context.Context, arg SelectAllAccountsParams) ([]Account, error)

func (*Queries) UpdateAccount

func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error)

func (*Queries) WithTx

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

type SelectAllAccountsParams

type SelectAllAccountsParams struct {
	Limit  int32
	Offset int32
}

type Session

type Session struct {
	Token  string
	Data   []byte
	Expiry time.Time
}

type UpdateAccountParams

type UpdateAccountParams struct {
	ID          uuid.UUID
	Email       pgtype.Text
	Password    pgtype.Text
	FullName    pgtype.Text
	PhoneNumber pgtype.Text
	Role        NullAccountRole
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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