db

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package db repository wrapper for go-pg orm this is intended to simplify unit testing and general code structure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

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

Repository is short for repository

func NewRepository

func NewRepository(conn *pg.DB) *Repository

NewRepository create new repository instance

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, model interface{}, values ...interface{}) (orm.Result, error)

Create make new model inside the database

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, values ...interface{}) (orm.Result, error)

Delete delete model from database

func (*Repository) Exec

func (r *Repository) Exec(ctx context.Context, query string, params ...interface{}) (orm.Result, error)

Exec run query on the database

func (*Repository) Find

func (r *Repository) Find(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, values ...interface{}) error

Find find the model in database

func (*Repository) SelectOrCreate

func (r *Repository) SelectOrCreate(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, values ...interface{}) (bool, error)

SelectOrCreate select model from db and create if not exists

func (*Repository) Transaction

func (r *Repository) Transaction(ctx context.Context, callback func(db *pg.Tx) error) error

Transaction run set of queries in transaction

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, fields ...interface{}) (orm.Result, error)

Update update fields for the model

Jump to

Keyboard shortcuts

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