store

package
v0.0.0-...-d904837 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTooManyAffectedRows returned when store modifes too many rows.
	ErrTooManyAffectedRows = errors.New("too many affected rows")
)
View Source
var ErrUserNotFound = errors.New("user not found")
View Source
var UserFields = dal.UserColumns

Functions

func Asc

func Asc(field string) string

func Desc

func Desc(field string) string

Types

type Base

type Base[M any, Q any] interface {
	// Add T to store.
	Add(ctx context.Context, v *M) error

	// Update T in store.
	Update(ctx context.Context, v *M, fields ...string) error

	// Query T from store.
	Query() Q
}

type BaseQuery

type BaseQuery[M any] interface {
	// Count all rows matching query.
	Count(ctx context.Context) (int, error)

	// Get all rows matching query.
	All(ctx context.Context) ([]*M, error)

	// Get first row matching query.
	One(ctx context.Context) (*M, error)

	// Delete all rows matching query.
	Delete(ctx context.Context) error
}

type Migrator

type Migrator interface {
	Up(ctx context.Context) error
	Down(ctx context.Context) error
}

Migrator defines generic interface for migrations.

type MigratorFactory

type MigratorFactory interface {
	Migrator() Migrator
}

MigratorFactory define method for migrations of store

type Store

type Store interface {
	StoreFactory
	StoreTx
	MigratorFactory
}

Store define generic interface for database with transaction support

type StoreFactory

type StoreFactory interface {
	User() User
}

StoreFactory define interface of factory methods

type StoreTx

type StoreTx interface {
	// TxFactory returns function for create transaction scopes.
	Tx(ctx context.Context, txFunc TxFunc) error
}

StoreTx define interface of transactional of store.

type TxFunc

type TxFunc func(ctx context.Context) error

TxFunc define signature of callback used in tx block

type Txier

type Txier func(ctx context.Context, txFunc TxFunc) error

Txier define function to start tx block

type User

type User interface {
	Base[domain.User, UserQuery]
}

type UserQuery

type UserQuery interface {
	BaseQuery[domain.User]

	ID(ids ...domain.UserID) UserQuery
	TelegramID(ids ...tg.UserID) UserQuery
}

Directories

Path Synopsis
dal

Jump to

Keyboard shortcuts

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