gocommon

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: Unlicense Imports: 7 Imported by: 0

README

go-common

The common package for Go language.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TypeConverter

func TypeConverter[T any](source any) (*T, error)

Types

type BaseRepository

type BaseRepository[T, ID any] struct {
	DB *gorm.DB
}

func NewBaseRepository

func NewBaseRepository[T, ID any](db *gorm.DB) *BaseRepository[T, ID]

func (BaseRepository[T, ID]) Create

func (r BaseRepository[T, ID]) Create(ctx context.Context, t *T) error

func (BaseRepository[T, ID]) CreateMany

func (r BaseRepository[T, ID]) CreateMany(ctx context.Context, t *[]T, size int) error

func (BaseRepository[T, ID]) Delete

func (r BaseRepository[T, ID]) Delete(ctx context.Context, t *T) (bool, error)

func (BaseRepository[T, ID]) Get

func (r BaseRepository[T, ID]) Get(ctx context.Context, id ID) (*T, error)

func (BaseRepository[T, ID]) GetList

func (r BaseRepository[T, ID]) GetList(ctx context.Context, filters interface{}, paging *PagingQuery) (int64, []T, error)

func (BaseRepository[T, ID]) GetListWithQuery

func (r BaseRepository[T, ID]) GetListWithQuery(ctx context.Context, query *gorm.DB, paging *PagingQuery) (int64, []T, error)

func (BaseRepository[T, ID]) QueryBuilder

func (r BaseRepository[T, ID]) QueryBuilder(query *gorm.DB, options interface{}) *gorm.DB

---------------------------------------- ---------------------------------------- QueryBuilder build additional query term ---------------------------------------- ----------------------------------------

func (BaseRepository[T, ID]) Update

func (r BaseRepository[T, ID]) Update(ctx context.Context, t *T) error

type BaseService

type BaseService[Entity, ID, Dto, CreateDto, UpdateDto, FilterDto any] struct {
	BaseRepository IBaseRepository[Entity, ID]
}

func (BaseService[Entity, PkType, Dto, CreateDto, UpdateDto, FilterDto]) Create

func (s BaseService[Entity, PkType, Dto, CreateDto, UpdateDto, FilterDto]) Create(ctx context.Context, input CreateDto) (Dto, error)

func (BaseService[Entity, PkType, Dto, CreateDto, UpdateDto, FilterDto]) Delete

func (s BaseService[Entity, PkType, Dto, CreateDto, UpdateDto, FilterDto]) Delete(ctx context.Context, id PkType) (bool, error)

func (BaseService[Entity, ID, Dto, CreateDto, UpdateDto, FilterDto]) Get

func (s BaseService[Entity, ID, Dto, CreateDto, UpdateDto, FilterDto]) Get(ctx context.Context, id ID) (*Dto, error)

func (BaseService[Entity, ID, Dto, CreateDto, UpdateDto, FilterDto]) GetList

func (s BaseService[Entity, ID, Dto, CreateDto, UpdateDto, FilterDto]) GetList(ctx context.Context, input FilterDto, query *PagingQuery) (PagedResultDto[Dto], error)

func (BaseService[Entity, PkType, Dto, CreateDto, UpdateDto, FilterDto]) Update

func (s BaseService[Entity, PkType, Dto, CreateDto, UpdateDto, FilterDto]) Update(ctx context.Context, id PkType, input UpdateDto) (Dto, error)

type IBaseRepository

type IBaseRepository[T, ID any] interface {
	Get(ctx context.Context, id ID) (*T, error)
	GetList(ctx context.Context, filters interface{}, paging *PagingQuery) (int64, []T, error)
	GetListWithQuery(ctx context.Context, query *gorm.DB, paging *PagingQuery) (int64, []T, error)
	Create(ctx context.Context, t *T) error
	CreateMany(ctx context.Context, t *[]T, size int) error
	Update(ctx context.Context, t *T) error
	Delete(ctx context.Context, t *T) (bool, error)
	QueryBuilder(query *gorm.DB, options interface{}) *gorm.DB
}

type IBaseService

type IBaseService[Entity, ID, Dto, CreateDto, UpdateDto, FilterDto any] interface {
	Get(ctx context.Context, id ID) (*Dto, error)
	GetList(ctx context.Context, input FilterDto, query *PagingQuery) (PagedResultDto[Dto], error)
	Create(ctx context.Context, input CreateDto) (Dto, error)
	Update(ctx context.Context, id ID, input UpdateDto) (Dto, error)
	Delete(ctx context.Context, id ID) (bool, error)
}

type PagedResultDto

type PagedResultDto[Dto any] struct {
	Total int64 `json:"total"`
	Items []Dto `json:"items"`
}

type PagingQuery

type PagingQuery struct {
	Page    int     `query:"page" form:"page"`
	Size    int     `query:"size" form:"size"`
	OrderBy *string `query:"order_by" form:"order_by" default:"desc"`
	SortBy  *string `query:"sort_by" form:"sort_by" default:"created_at"`
}

func NewPagingQuery

func NewPagingQuery() PagingQuery

type PagingResult

type PagingResult struct {
	Items interface{} `json:"items"`
	Total int64       `json:"total"`
}

Jump to

Keyboard shortcuts

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