db

package
v0.0.0-...-30054f4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package db is a generated GoMock package.

Index

Constants

View Source
const (
	SortOrderAsc  = "ASC"
	SortOrderDesc = "DESC"
)

Variables

View Source
var PgDialect = goqu.Dialect("postgres")

Functions

func ScanRows

func ScanRows[T any](rows pgx.Rows, scanner func(row PgxScanner) (*T, error)) ([]*T, error)

Types

type IQuery

type IQuery interface {
	Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

IQuery interface for make db queires

type MockIQuery

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

MockIQuery is a mock of IQuery interface.

func NewMockIQuery

func NewMockIQuery(ctrl *gomock.Controller) *MockIQuery

NewMockIQuery creates a new mock instance.

func (*MockIQuery) EXPECT

func (m *MockIQuery) EXPECT() *MockIQueryMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockIQuery) Exec

func (m *MockIQuery) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)

Exec mocks base method.

func (*MockIQuery) Query

func (m *MockIQuery) Query(ctx context.Context, sql string, args ...any) (v5.Rows, error)

Query mocks base method.

func (*MockIQuery) QueryRow

func (m *MockIQuery) QueryRow(ctx context.Context, sql string, args ...any) v5.Row

QueryRow mocks base method.

type MockIQueryMockRecorder

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

MockIQueryMockRecorder is the mock recorder for MockIQuery.

func (*MockIQueryMockRecorder) Exec

func (mr *MockIQueryMockRecorder) Exec(ctx, sql any, arguments ...any) *gomock.Call

Exec indicates an expected call of Exec.

func (*MockIQueryMockRecorder) Query

func (mr *MockIQueryMockRecorder) Query(ctx, sql any, args ...any) *gomock.Call

Query indicates an expected call of Query.

func (*MockIQueryMockRecorder) QueryRow

func (mr *MockIQueryMockRecorder) QueryRow(ctx, sql any, args ...any) *gomock.Call

QueryRow indicates an expected call of QueryRow.

type MockPgxScanner

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

MockPgxScanner is a mock of PgxScanner interface.

func NewMockPgxScanner

func NewMockPgxScanner(ctrl *gomock.Controller) *MockPgxScanner

NewMockPgxScanner creates a new mock instance.

func (*MockPgxScanner) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPgxScanner) Scan

func (m *MockPgxScanner) Scan(dest ...any) error

Scan mocks base method.

type MockPgxScannerMockRecorder

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

MockPgxScannerMockRecorder is the mock recorder for MockPgxScanner.

func (*MockPgxScannerMockRecorder) Scan

func (mr *MockPgxScannerMockRecorder) Scan(dest ...any) *gomock.Call

Scan indicates an expected call of Scan.

type MockTxRepository

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

MockTxRepository is a mock of TxRepository interface.

func NewMockTxRepository

func NewMockTxRepository(ctrl *gomock.Controller) *MockTxRepository

NewMockTxRepository creates a new mock instance.

func (*MockTxRepository) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTxRepository) GetDb

func (m *MockTxRepository) GetDb(ctx context.Context) IQuery

GetDb mocks base method.

func (*MockTxRepository) GetNative

func (m *MockTxRepository) GetNative() *pgxpool.Pool

GetNative mocks base method.

func (*MockTxRepository) Lock

func (m *MockTxRepository) Lock(ctx context.Context, table, code string) error

Lock mocks base method.

func (*MockTxRepository) TryLock

func (m *MockTxRepository) TryLock(ctx context.Context, table, code string) (bool, error)

TryLock mocks base method.

func (*MockTxRepository) TxLock

func (m *MockTxRepository) TxLock(ctx context.Context, table, code string) error

TxLock mocks base method.

func (*MockTxRepository) Unlock

func (m *MockTxRepository) Unlock(ctx context.Context, table, code string) (bool, error)

Unlock mocks base method.

func (*MockTxRepository) WithTx

func (m *MockTxRepository) WithTx(ctx context.Context, handler func(context.Context) error) error

WithTx mocks base method.

type MockTxRepositoryMockRecorder

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

MockTxRepositoryMockRecorder is the mock recorder for MockTxRepository.

func (*MockTxRepositoryMockRecorder) GetDb

func (mr *MockTxRepositoryMockRecorder) GetDb(ctx any) *gomock.Call

GetDb indicates an expected call of GetDb.

func (*MockTxRepositoryMockRecorder) GetNative

func (mr *MockTxRepositoryMockRecorder) GetNative() *gomock.Call

GetNative indicates an expected call of GetNative.

func (*MockTxRepositoryMockRecorder) Lock

func (mr *MockTxRepositoryMockRecorder) Lock(ctx, table, code any) *gomock.Call

Lock indicates an expected call of Lock.

func (*MockTxRepositoryMockRecorder) TryLock

func (mr *MockTxRepositoryMockRecorder) TryLock(ctx, table, code any) *gomock.Call

TryLock indicates an expected call of TryLock.

func (*MockTxRepositoryMockRecorder) TxLock

func (mr *MockTxRepositoryMockRecorder) TxLock(ctx, table, code any) *gomock.Call

TxLock indicates an expected call of TxLock.

func (*MockTxRepositoryMockRecorder) Unlock

func (mr *MockTxRepositoryMockRecorder) Unlock(ctx, table, code any) *gomock.Call

Unlock indicates an expected call of Unlock.

func (*MockTxRepositoryMockRecorder) WithTx

func (mr *MockTxRepositoryMockRecorder) WithTx(ctx, handler any) *gomock.Call

WithTx indicates an expected call of WithTx.

type Pagination

type Pagination struct {
	All     *bool
	Page    int
	PerPage int
}

func (Pagination) Apply

func (Pagination) GetLimit

func (p Pagination) GetLimit() int

func (Pagination) GetOffset

func (p Pagination) GetOffset() int

func (Pagination) GetPage

func (p Pagination) GetPage() int

func (Pagination) GetPerPage

func (p Pagination) GetPerPage() int

type PgxScanner

type PgxScanner interface {
	Scan(dest ...any) error
}

type Postgres

type Postgres struct {
	Pool *pgxpool.Pool
	DB   *sql.DB
}

Postgres

func NewPostgresClient

func NewPostgresClient(ctx context.Context, cfg config.Postgres) (*Postgres, error)

NewPostgresClient create pool pgx and database/sql over it.

func (*Postgres) Close

func (p *Postgres) Close() error

Close closes the pgx pool. stdlib.OpenDBFromPool does not close the pool on sql.DB.Close().

type Sorting

type Sorting struct {
	Sort      string
	SortOrder string
}

func (Sorting) Apply

func (s Sorting) Apply(tableConfig TableConfig[any], q *goqu.SelectDataset) *goqu.SelectDataset

func (Sorting) ApplyColumn

func (s Sorting) ApplyColumn(tableConfig TableConfig[any], column string, q *goqu.SelectDataset) *goqu.SelectDataset

func (Sorting) GetOrderBy

func (s Sorting) GetOrderBy(tableConfig TableConfig[any]) (string, string)

func (Sorting) GetSortOrder

func (s Sorting) GetSortOrder() string

type TableConfig

type TableConfig[T any] struct {
	Name          string
	Alias         string
	InsertFields  []any
	SelectFields  []any
	UpdatedFields []any
	DefaultSort   string
	SortingFields map[string]bool // true for nulls last
	InsertValues  func(item *T) [][]any
	UpdateValues  func(item *T) *goqu.Record
}

type TimestampFilter

type TimestampFilter struct {
	LastID      int64
	CreatedFrom *time.Time
	CreatedTo   *time.Time
	UpdatedFrom *time.Time
	UpdatedTo   *time.Time
}

TimestampFilter фильтр по дате создания и обновления записи.

func (TimestampFilter) Apply

func (t TimestampFilter) Apply(
	filters []goqu.Expression,
	createdAtCol exp.IdentifierExpression,
	updatedAtCol exp.IdentifierExpression,
) []goqu.Expression

type TimestampSearchRequest

type TimestampSearchRequest struct {
	LastID      int64  `json:"last_id" query:"last_id"`
	CreatedFrom string `json:"created_from" query:"created_from"`
	CreatedTo   string `json:"created_to" query:"created_to"`
	UpdatedFrom string `json:"updated_from" query:"updated_from"`
	UpdatedTo   string `json:"updated_to" query:"updated_to"`
}

TimestampSearchRequest параметры фильтрации по дате создания и обновления.

func (TimestampSearchRequest) ToTimestampFilter

func (t TimestampSearchRequest) ToTimestampFilter() TimestampFilter

type TxRepository

type TxRepository interface {
	WithTx(ctx context.Context, handler func(ctx context.Context) error) error
	GetDb(ctx context.Context) IQuery
	GetNative() *pgxpool.Pool
	Lock(ctx context.Context, table, code string) error
	TxLock(ctx context.Context, table, code string) error
	TryLock(ctx context.Context, table, code string) (bool, error)
	Unlock(ctx context.Context, table, code string) (bool, error)
}

TxRepository interface for extends repository interfaces

func NewTxRepository

func NewTxRepository(dbpool *pgxpool.Pool) TxRepository

NewTxRepository wraps a repository for transactional execution

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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