storage

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 5 Imported by: 1

README

storage

Documentation

Index

Constants

View Source
const (
	ErrEmptyResult = errors.Const("empty query result")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	// Storage - возвращает клиента базы данных
	Storage(dsn string) (Storage, error)
}

Factory - абстрактная фабрика клиентов

type Iterator

type Iterator interface {
	io.Closer
	// Next - перемещает курсор итератора на следующий элемент
	Next(ctx context.Context) bool
	// Err - возвращает ошибку итератора, если такая имела место
	Err() error
	// Decode приводит значение текущего элемента итерации к указанному типу
	Decode(result any) error
}

Iterator интерфейс итератора по многоэлементному результату запроса

type Query

type Query interface {
	fmt.Stringer
	// Query - возвращает запрос
	Query() interface{}
	// Params Возвращает параметры запроса
	Params() interface{}
}

type Result added in v1.0.5

type Result []map[string]any

type Storage

type Storage interface {
	io.Closer
	// Begin Стартует и возвращает новую транзакцию
	Begin(ctx context.Context, opts ...any) (transaction Transaction, err error)
	// Exec Выполняет запрос который ничего не возвращает
	Exec(ctx context.Context, query Query) (sql.Result, error)
	// Query - выполняет запрос производящий действия в базе, с возможностью вернуть произвольный результат
	Query(ctx context.Context, query Query, result any) error
	// Iterate возвращает итератор по результату запроса
	Iterate(ctx context.Context, query Query) (Iterator, error)
}

type Table added in v1.0.5

type Table struct {
	Headers []string
	Rows    [][]any
}

type Transaction

type Transaction interface {
	// Context - возвращает контекст транзакции
	Context() context.Context
	// Commit Фиксирует текущую транзакцию
	Commit(ctx context.Context) error
	// Rollback Откатывает текущую транзакцию
	Rollback(ctx context.Context) error
}

Transaction интерфейс транзакции базы данных

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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