db

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 7 Imported by: 0

README

For run integration test with real Postgres (docker container)

make tests

For more information -> Makefile

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRepoEmptyRepo = errors.New("invalid repo (empty repo). Not registered?" +
		" Check this usage connector.AddAllowsRepos(repos ...db.Table)")
	ErrMismatchRowsCnt = errors.New("mismatch rows counts")
	ErrZeroPageSize    = errors.New("zero value of params.PageSize")
	ErrZeroLimitSize   = errors.New("zero value of params.Limit")
)

Functions

This section is empty.

Types

type Alias

type Alias = string

Alias - alias for table.

type Argument

type Argument = any

Argument - anything ibj which have Valuer and Scan.

type BaseRepositoryI

type BaseRepositoryI interface {
	Name() Table // Name of table/repo (repo obj)

	GetRowsByQuery(ctx context.Context, qb SelectBuilder) (*sql.Rows, error)
	CountByQuery(ctx context.Context, qb SelectBuilder) (uint64, error)

	Insert(context.Context, []Column, []Argument) (int64, error)
	UpdateCustom(context.Context, map[string]any, Condition) (int64, error)
}

BaseRepositoryI - base method for all type Repo's

type Column

type Column = string

Column - sql column name.

type Condition

type Condition = squirrel.Sqlizer // squirrel.Eq or squirrel.Gt or squirrel.And and etc

Condition - squirrel.Sqlizer

type Config

type Config = interface {
	IsEnableValidationRepoNames() bool
	IsEnableReposCache() bool
	PlaceholderFormat() PlaceholderFormat // squirrel int code for placeholder
}

Config - configuration obj for Storage

type Connector

type Connector[C Config] interface {
	Config() C

	AddAllowsRepos(...Table)
	GetAllowsRepos() []Table
	IsAllowRepo(Table) bool

	Logger() Logger

	Connection() PureSqlxConnection

	Repo(DTO) Repository // TODO think about -> optional.Optional[Repository]

	RepoByName(Table) Repository

	AutoCreate(context.Context, DTO) (int64, error)
	AutoGet(context.Context, DTO) error
	AutoUpdate(context.Context, DTO) (int64, error)
	AutoDelete(context.Context, DTO) (int64, error)
}

Connector - entity for describe connection to specific DB instance

type CursorPaginationParams

type CursorPaginationParams struct {
	Limit     uint64
	Cursor    uint64
	DescOrder bool
}

type DTO

type DTO interface {
	Repo() Table
	Identity() ID
}

type GDTO

type GDTO[I ID] interface {
	ID() I
	DTO
}

type GRepository

type GRepository[I ID, D DTO] interface {
	BaseRepositoryI

	Create(context.Context, D) (I, error)
	Get(context.Context, I) (D, error)
	Update(context.Context, I, D) (int64, error)
	Delete(context.Context, I) (int64, error)

	FindBy(context.Context, []Column, Condition) ([]D, error)
	FindOneBy(context.Context, []Column, Condition) (D, error)

	Select(context.Context, SelectBuilder) ([]D, error)
	SelectWithPagePagination(context.Context, SelectBuilder, PagePaginationParams) ([]D, PagePaginationResults, error)
	SelectWithCursorOnPKPagination(context.Context, SelectBuilder, CursorPaginationParams) ([]D, error)
}

GRepository - methods for new (modern) approach generic based Repo's

type ID

type ID = any

ID - uniq ID

type Join

type Join = string

Join - join part of query.

type Logger

type Logger = *zap.Logger

Logger - Uber Zap logger

type Obj

type Obj = any

Obj - any obj (any).

type PagePaginationParams

type PagePaginationParams struct {
	PageNumber uint64
	PageSize   uint64
}

type PagePaginationResults

type PagePaginationResults struct {
	CurrentPageNumber uint64
	NextPageNumber    uint64
	CntPages          uint64
}

type PlaceholderFormat

type PlaceholderFormat = squirrel.PlaceholderFormat

PlaceholderFormat - squirrel.PlaceholderFormat

type Query

type Query = string

Query - sql query string.

type Repository

type Repository interface {
	BaseRepositoryI

	Create(context.Context, any) (int64, error) // todo add one method for ID = string or move to generics API only
	Get(context.Context, ID, any) error
	Update(context.Context, ID, any) (int64, error)
	Delete(context.Context, ID) (int64, error)

	FindBy(context.Context, []Column, Condition, any) error
	FindOneBy(context.Context, []Column, Condition, any) error

	FindByWithInnerJoin(context.Context, []Column, Alias, Join, Condition, any) error
	FindOneByWithInnerJoin(context.Context, []Column, Alias, Join, Condition, any) error

	Select(context.Context, SelectBuilder, any) error
	SelectWithPagePagination(context.Context, SelectBuilder, PagePaginationParams, any) (PagePaginationResults, error)
	SelectWithCursorOnPKPagination(context.Context, SelectBuilder, CursorPaginationParams, any) error
}

Repository - methods for classic Repo's (non generics)

type SelectBuilder

type SelectBuilder = squirrel.SelectBuilder

SelectBuilder - squirrel.SelectBuilder

type Storage

type Storage[C Config] interface {
	Config() C

	Connect() error
	Reconnect() error

	OnConnect(context.Context, func()) error   // actions that will be performed after function call Connect()
	OnReconnect(context.Context, func()) error // actions that will be performed after function call Reconnect()
	OnStop(context.Context, func()) error      // actions that will be performed after function call Close()

	Master() Connector[C]
	Slaves() []Connector[C]

	Close() error
}

Storage - abstract Storage interface general storage interface.

type Table

type Table = string

Table - sql table

Directories

Path Synopsis
example
genrepo
empty
Package empty used for realization absent Optional[T] pattern
Package empty used for realization absent Optional[T] pattern

Jump to

Keyboard shortcuts

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