persistence

package
v0.0.0-...-29e199f Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package persistence defines the framework to interact with the database storage.

Index

Constants

View Source
const (
	// Asc ascendant direction order
	Asc OrderDirection = "asc"
	// Desc descendant direction order
	Desc OrderDirection = "desc"
	// CreationDate creation date order
	CreationDate OrderByOption = "creation_date"
	// LastUpdate update date order
	LastUpdate OrderByOption = "last_update"
)

Variables

This section is empty.

Functions

func IsAlreadyExists

func IsAlreadyExists(err error) bool

func IsCanNotBeginTransaction

func IsCanNotBeginTransaction(err error) bool

func IsCanNotCommitTransaction

func IsCanNotCommitTransaction(err error) bool

func IsCanNotRollbackTransaction

func IsCanNotRollbackTransaction(err error) bool

func IsConfigCanNotBeLoaded

func IsConfigCanNotBeLoaded(err error) bool

func IsDBResponseCouldNotBeProcessed

func IsDBResponseCouldNotBeProcessed(err error) bool

func IsEntryNotAdded

func IsEntryNotAdded(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsPermanentConnectionError

func IsPermanentConnectionError(err error) bool

func IsStatementCouldNotBePrepared

func IsStatementCouldNotBePrepared(err error) bool

func IsStatementExecutionFailed

func IsStatementExecutionFailed(err error) bool

func IsTransientConnectionError

func IsTransientConnectionError(err error) bool

func IsTxNotInContext

func IsTxNotInContext(err error) bool

Types

type BetweenFilter

type BetweenFilter struct {
	By       string
	MinValue string
	MaxValue string
}

BetweenFilter to filter by the specified field between two values

func (BetweenFilter) ToSQLStmt

func (f BetweenFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type EqualFilter

type EqualFilter struct {
	By string
}

EqualFilter to filter by the specified field with equal value

func (EqualFilter) ToSQLStmt

func (f EqualFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type Error

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

Error for the persistence framework

func NewAlreadyExistsError

func NewAlreadyExistsError() *Error

func NewCanNotBeginTransactionError

func NewCanNotBeginTransactionError() *Error

func NewCanNotCommitTransactionError

func NewCanNotCommitTransactionError() *Error

func NewCanNotRollbackTransactionError

func NewCanNotRollbackTransactionError() *Error

func NewConfigCanNotBeLoadedError

func NewConfigCanNotBeLoadedError() *Error

func NewDBResponseCanNotBeProcessedError

func NewDBResponseCanNotBeProcessedError() *Error

func NewEntryNotAddedError

func NewEntryNotAddedError() *Error

func NewNotFoundError

func NewNotFoundError() *Error

func NewPermanentConnectionError

func NewPermanentConnectionError() *Error

func NewStatementCouldNotBePreparedError

func NewStatementCouldNotBePreparedError() *Error

func NewStatementExecutionFailedError

func NewStatementExecutionFailedError() *Error

func NewTransientConnectionError

func NewTransientConnectionError() *Error

func NewTxNotInContextError

func NewTxNotInContextError() *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) WithMessage

func (e *Error) WithMessage(message string) *Error

type ExecuteStmtWithStorageResultOutput

type ExecuteStmtWithStorageResultOutput struct {
	Result sql.Result
}

ExecuteStmtWithStorageResultOutput wraps the result of an statement

type Filter

type Filter interface {
	// ToSQLStmt SQL statement for the filter
	ToSQLStmt() string
}

Filter defines the functionality to convert filters into statements

type FilterGroup

type FilterGroup struct {
	Filters []Filter
}

FilterGroup defines the group of filters Storage data

type FilterOption

type FilterOption string

FilterOption defines a filter option

type GreaterFilter

type GreaterFilter struct {
	By string
}

GreaterFilter to filter by the specified field with greater value

func (GreaterFilter) ToSQLStmt

func (f GreaterFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type GreaterOrEqualFilter

type GreaterOrEqualFilter struct {
	By string
}

GreaterOrEqualFilter to filter by the specified field with greater or equal value

func (GreaterOrEqualFilter) ToSQLStmt

func (f GreaterOrEqualFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type LessFilter

type LessFilter struct {
	By string
}

LessFilter to filter by the specified field with less value

func (LessFilter) ToSQLStmt

func (f LessFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type LessOrEqualFilter

type LessOrEqualFilter struct {
	By string
}

LessOrEqualFilter to filter by the specified field with less or equal value

func (LessOrEqualFilter) ToSQLStmt

func (f LessOrEqualFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type ListEqualFilter

type ListEqualFilter struct {
	By     string
	Values []string
}

ListEqualFilter to filter by the specified field with a list of possible value

func (ListEqualFilter) ToSQLStmt

func (f ListEqualFilter) ToSQLStmt() string

ToSQLStmt SQL statement for the filter

type MapperConfig

type MapperConfig struct {
	ID         string            `xml:"id,attr"`
	Statements []StatementConfig `xml:"statement"`
}

MapperConfig identifies a mapper configuration for a set of StatementConfig

type Order

type Order struct {
	By        OrderByOption  `valid:"required"`
	Direction OrderDirection `valid:"required"`
}

Order defines order on Storage data

type OrderByOption

type OrderByOption string

OrderByOption defines the field to apply order

type OrderDirection

type OrderDirection string

OrderDirection defines the order direction

type Pagination

type Pagination struct {
	// Limit maximum number of entries to return
	Limit int `valid:"required"`
	// Offset zero-based offset of the first item in the collection to return
	Offset int `valid:"required"`
}

Pagination from the Storage data with limit/offset navigation

type ReadDirAndFileFS

type ReadDirAndFileFS interface {
	fs.ReadDirFS
	fs.ReadFileFS
}

type StatementConfig

type StatementConfig struct {
	ID      string `xml:"id,attr"`
	Content string `xml:",chardata"`
}

StatementConfig identifies a statement configuration

type Storage

type Storage interface {
	// QueryAll obtains all element from statement with arguments provided. It returns an error if it fails
	QueryAll(ctx context.Context, stmtID string, args interface{}, dst interface{}) error
	// ExecuteStmt executes statement with arguments provided. It returns an error if it fails
	ExecuteStmt(ctx context.Context, stmtID string, args interface{}) error
	// ExecuteStmtWithStorageResult executes statement with arguments provided. It returns information on stmt or an error if it fails
	ExecuteStmtWithStorageResult(ctx context.Context, stmtID string, args interface{}) (*ExecuteStmtWithStorageResultOutput, error)
	// BeginTransaction starts a Storage operation that is transactional. It returns an error if it fails
	BeginTransaction(ctx context.Context) (context.Context, error)
	// RollbackTransaction rollbacks to previous state a Storage operation that is transactional. It returns an error if it fails
	RollbackTransaction(ctx context.Context) error
	// CommitTransaction confirms a Storage operation that is transactional. It returns an error if it fails
	CommitTransaction(ctx context.Context) error
	// GetTransaction returns the transaction from context (in case of success).
	GetTransaction(ctx context.Context) (any, error)
	// AddConfig registers SQL statements
	AddConfig(config StorageConfig) error
}

type StorageConfig

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

StorageConfig configuration for StatementConfig

func NewEmptyStorageConfig

func NewEmptyStorageConfig() StorageConfig

NewEmptyStorageConfig returns an empty StorageConfig

func NewStorageConfig

func NewStorageConfig(options StorageConfigOptions) (*StorageConfig, error)

NewStorageConfig returns a new StorageConfig with the provided configuration options.

func (*StorageConfig) AddConfig

func (config *StorageConfig) AddConfig(newFwConfig StorageConfig) error

AddConfig adds a new configuration to the configurations data map.

func (*StorageConfig) GetStatement

func (config *StorageConfig) GetStatement(id string) (StatementConfig, bool)

GetStatement obtain the StatementConfig with the AdminID provided

type StorageConfigOptions

type StorageConfigOptions struct {
	ReadDirAndFileFS ReadDirAndFileFS
	MappersPath      string
	Driver           string
}

Directories

Path Synopsis
Package dbmigrator defines the functionalities for database migrations.
Package dbmigrator defines the functionalities for database migrations.
sql
Package sql defines the SQL database management utilities.
Package sql defines the SQL database management utilities.
postgres
Package postgres defines the PostgresSQL functionalities.
Package postgres defines the PostgresSQL functionalities.
sqlite
Package sqlite defines the SQLite database functionality to operate with.
Package sqlite defines the SQLite database functionality to operate with.

Jump to

Keyboard shortcuts

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