shelter

package
v0.0.0-...-0e46809 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid configuration: missing required fields")

Functions

func Connection

func Connection(ctx context.Context, pool *pgxpool.Pool) (*pgx.Conn, error)

func DatabasePool

func DatabasePool(ctx context.Context, cfg Config, ping bool) (*pgxpool.Pool, error)

Decide to ping db on creating connection pool or not.

func Ping

func Ping(ctx context.Context, pool *pgxpool.Pool) error

Types

type Config

type Config struct {
	Host     string `mapstructure:"DB_HOST"`
	Port     string `mapstructure:"DB_PORT"`
	User     string `mapstructure:"DB_USER"`
	Password string `mapstructure:"DB_PASSWORD"`
	DBName   string `mapstructure:"DB_NAME"`
}

func NewConfig

func NewConfig(host, port, user, password, dbname string) Config

type CreateDogParams

type CreateDogParams struct {
	Name  string `json:"name"`
	Breed string `json:"breed"`
}

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 Dog

type Dog struct {
	ID        int64              `json:"id"`
	Name      string             `json:"name"`
	Breed     string             `json:"breed"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
	UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}

func (Dog) String

func (d Dog) String() string

type Querier

type Querier interface {
	AllDogs(ctx context.Context) ([]Dog, error)
	CreateDog(ctx context.Context, arg CreateDogParams) (Dog, error)
	DeleteDog(ctx context.Context, name string) error
	ReadDog(ctx context.Context, name string) (Dog, error)
	UpdateDog(ctx context.Context, arg UpdateDogParams) (Dog, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AllDogs

func (q *Queries) AllDogs(ctx context.Context) ([]Dog, error)

func (*Queries) CreateDog

func (q *Queries) CreateDog(ctx context.Context, arg CreateDogParams) (Dog, error)

func (*Queries) DeleteDog

func (q *Queries) DeleteDog(ctx context.Context, name string) error

func (*Queries) ReadDog

func (q *Queries) ReadDog(ctx context.Context, name string) (Dog, error)

func (*Queries) UpdateDog

func (q *Queries) UpdateDog(ctx context.Context, arg UpdateDogParams) (Dog, error)

func (*Queries) WithTx

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

type UpdateDogParams

type UpdateDogParams struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Breed string `json:"breed"`
}

Jump to

Keyboard shortcuts

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