repository

package
v0.8.24 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BookColumns = bookColumns{
	ID:        "id",
	Title:     "title",
	Author:    "author",
	UpdatedAt: "updated_at",
	CreatedAt: "created_at",
}

Functions

This section is empty.

Types

type Book

type Book struct {
	ID        int64     `json:"id"`
	Title     string    `json:"title" validate:"required"`
	Author    string    `json:"author" validate:"required"`
	UpdatedAt time.Time `json:"update_at"`
	CreatedAt time.Time `json:"created_at"`
}

Book represented database model

type BookRepo

type BookRepo interface {
	FindOne(context.Context, int64) (*Book, error)
	Find(context.Context, ...dbkit.FindOption) ([]*Book, error)
	Create(context.Context, *Book) (*Book, error)
	Delete(context.Context, int64) error
	Update(context.Context, *Book) (*Book, error)
}

BookRepo to get book data from database [mock]

func NewBookRepo

func NewBookRepo(impl BookRepoImpl) BookRepo

NewBookRepo return new instance of BookRepo [constructor]

type BookRepoImpl

type BookRepoImpl struct {
	dig.In
	*typpostgres.DB
}

BookRepoImpl is implementation book repository

func (*BookRepoImpl) Create

func (r *BookRepoImpl) Create(ctx context.Context, new *Book) (book *Book, err error)

Create book

func (*BookRepoImpl) Delete

func (r *BookRepoImpl) Delete(ctx context.Context, id int64) (err error)

Delete book

func (*BookRepoImpl) Find

func (r *BookRepoImpl) Find(ctx context.Context, opts ...dbkit.FindOption) (list []*Book, err error)

Find book

func (*BookRepoImpl) FindOne

func (r *BookRepoImpl) FindOne(ctx context.Context, id int64) (book *Book, err error)

FindOne book

func (*BookRepoImpl) Update

func (r *BookRepoImpl) Update(ctx context.Context, update *Book) (book *Book, err error)

Update book

type Transactional

type Transactional struct {
	dig.In
	*sql.DB
}

Transactional database

func (*Transactional) CancelMe

func (t *Transactional) CancelMe(ctx context.Context, err error) error

CancelMe is store error to context to trigger the rollback mechanism

func (*Transactional) CommitMe

func (t *Transactional) CommitMe(ctx *context.Context) func() error

CommitMe to create begin transaction and return commit function to be deffered

Jump to

Keyboard shortcuts

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