db

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("record not found")
	ErrKeyConflict = errors.New("key conflict")
	ErrNoRowsUpd   = errors.New("no rows updated")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Name         string `env:"DB_NAME,default=cribe" json:",omitempty"`
	User         string `env:"DB_USER,default=postgres" json:",omitempty"`
	Host         string `env:"DB_HOST,default=localhost" json:",omitempty"`
	Port         int    `env:"DB_PORT,default=5430" json:",omitempty"`
	SSLMode      string `env:"DB_SSLMODE,default=disable" json:",omitempty"`
	ConnTimeout  int    `env:"DB_CONN_TIMEOUT,default=5" json:",omitempty"`
	Password     string `env:"DB_PASSWORD,default=postgres" json:"-"`
	PoolMinConns int    `env:"DB_POOL_MIN_CONNS,default=10" json:",omitempty"`
	PoolMaxConns int    `env:"DB_POOL_MAX_CONNS,default=50" json:",omitempty"`
}

func (Config) ConnectionURL

func (c Config) ConnectionURL() string

type DB

type DB struct {
	Pool *pgxpool.Pool
}

func New

func New(cfg *Config) (*DB, error)

New return DB instance with context.Background and DB config

func NewFromEnv

func NewFromEnv(ctx context.Context, cfg *Config) (*DB, error)

NewFromEnv return DB instance with context and DB config

func (*DB) Close

func (db *DB) Close()

func (*DB) InTx

func (db *DB) InTx(ctx context.Context, isoLevel pgx.TxIsoLevel, f func(tx pgx.Tx) error) error

InTx wraps the function in the DB into a transaction. Keeps track of resource cleanup and do rollback

type Metadata

type Metadata struct {
	VideoID   string
	Quality   string
	Mime      string
	FileID    string
	Params    VideoParams
	CreatedAt time.Time
	UpdatedAt time.Time
}

type MetadataRepository

type MetadataRepository struct {
	*DB
}

func NewMetadataRepository

func NewMetadataRepository(DB *DB) *MetadataRepository

func (*MetadataRepository) FetchByMetadata

func (m *MetadataRepository) FetchByMetadata(
	ctx context.Context, videoID string, mime string, quality string,
) (Metadata, error)

func (*MetadataRepository) Save

func (m *MetadataRepository) Save(ctx context.Context, model Metadata) error

type VideoParams

type VideoParams struct {
	Title    string `json:"title"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	Duration int    `json:"duration"`
	Thumb    string `json:"thumb"`
}

Jump to

Keyboard shortcuts

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