Documentation ¶
Overview ¶
Package db repository wrapper for go-pg orm this is intended to simplify unit testing and general code structure
Index ¶
- type Repository
- func (r *Repository) Create(ctx context.Context, model interface{}, values ...interface{}) (orm.Result, error)
- func (r *Repository) Delete(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, ...) (orm.Result, error)
- func (r *Repository) Exec(ctx context.Context, query string, params ...interface{}) (orm.Result, error)
- func (r *Repository) Find(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, ...) error
- func (r *Repository) SelectOrCreate(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, ...) (bool, error)
- func (r *Repository) Transaction(ctx context.Context, callback func(db *pg.Tx) error) error
- func (r *Repository) Update(ctx context.Context, model interface{}, modifier func(*orm.Query) *orm.Query, ...) (orm.Result, error)
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
Click to show internal directories.
Click to hide internal directories.