Documentation
¶
Index ¶
- Constants
- Variables
- func InstanceRedis() *redis.Client
- func NewCacheRedis()
- func NewConnectionDB(databaseURL string, poolConfig *PoolConfig) error
- type Cache
- type ConnectionDB
- type FieldMapping
- type Filter
- type FilterParams
- type Filters
- type FloatValue
- type IntValue
- type ObjectManager
- func (q *ObjectManager[T]) ExecuteListQuery(instance *sql.DB) ([]T, error)
- func (q *ObjectManager[T]) ExecutePagedQuery(instance *sql.DB) (*Page[T], error)
- func (q *ObjectManager[T]) ExecuteUniqueResultQuery(instance *sql.DB) (*T, error)
- func (q *ObjectManager[T]) List() ([]T, error)
- func (q *ObjectManager[T]) PagedList() (*Page[T], error)
- func (q *ObjectManager[T]) UniqueResult() (*T, error)
- func (q *ObjectManager[T]) WithCache(cache *Cache[T]) *ObjectManager[T]
- func (q *ObjectManager[T]) WithPage(page *PageRequest) *ObjectManager[T]
- type Page
- type PageRequest
- type PoolConfig
- type Query
- type QueryMapping
- type QueryParam
- type Sort
- type SortDirection
- type Statement
- type StringValue
- type Transaction
Constants ¶
View Source
const ( ErrDatabaseNotInitialized string = "database connection not initialized" ErrMsgFailedConnect string = "failed to connect to PostgreSQL: %w" ErrMsgFailedConnectionPig string = "failed to connect to PostgreSQL ping: %w" ErrMsgMigration string = "an error occurred when validate database migrations: %v" ErrMsgQueryIsEmpty string = "query is empty" ErrPageIsEmpty string = "page is empty, please create a pageable query" ErrMsgStmClose string = "failed to close statement: %v\n" )
View Source
const ( MAX_OPEN_CONNS = 10 // Número máximo de conexões abertas MAX_IDLE_CONNS = 5 // Número máximo de conexões inativas no pool MAX_CONN_LIFE_TIME = time.Minute * 5 // Tempo máximo de vida de uma conexão no pool )
View Source
const ( ErrMsgInvalidLogialOp = "invalid logical operator: %s" ErrMsgInvalidField = "invalid field: %s" ErrMsgInvalidCondition = "invalid condition: %s" ErrMsgUnsupportedTypeField = "unsupported value type for field" ErrMsgActionNotAllowed = "action not allowed, invalid value for a filter: %s" ErrMsgInvalidSortingField = "invalid sorting field: %s" )
View Source
const ( Eq = "=" LessOrEqual = "<=" GreaterOrEqual = ">=" NotEqual = "!=" In = "IN" Contains = "LIKE" Between = "BETWEEN" )
View Source
const ( Or = "OR" And = "AND" )
View Source
const ( ErrMsgCouldNotConnectDB string = "could not connect to database for migration %v" ErrMsgMigrationExecutionWithError string = "an error occurred during migration execution: %v" ErrMsgCreateMigrateInstance string = "failed to create migrate instance" )
View Source
const ( DefaultPage = uint16(0) DefaultLimit = uint16(15) DefaultSortField = "id" DefaultSortDirection = string(ASC) )
View Source
const ( SqlTxContextKey contextKey = "sqlTxContext" MsgTransactionIsolationIgnored = "transaction isolation only uses the first parameter, others are ignored" ErrExecuteTransaction = "error when executing transaction error: %w" ErrTransactionRollback = "error when executing transaction rollback: %v, original error: %w" ErrTransactionCommit = "could not commit transaction: %w" ErrTransactionStart = "could not start database transaction: %v" )
Variables ¶
View Source
var (
NOT_ALLOWED_VALUES = []string{"DROP", "DELETE", "UPDATE", "INSERT", "ALTER", "TRUNCATE", "EXEC", "MERGE"}
)
Functions ¶
func InstanceRedis ¶
func InstanceRedis() *redis.Client
func NewCacheRedis ¶
func NewCacheRedis()
func NewConnectionDB ¶
func NewConnectionDB(databaseURL string, poolConfig *PoolConfig) error
Types ¶
type ConnectionDB ¶
type ConnectionDB struct {
// contains filtered or unexported fields
}
func InstanceDatabase ¶
func InstanceDatabase() *ConnectionDB
type FieldMapping ¶
type Filter ¶
type FilterParams ¶
type Filters ¶
type Filters struct { Params *FilterParams `json:"params"` Filters []*Filter `json:"filters"` }
func NewFilters ¶
func NewFilters() *Filters
type FloatValue ¶
type FloatValue float64 // currency
type ObjectManager ¶
type ObjectManager[T any] struct { // contains filtered or unexported fields }
func FindWithFilter ¶
func FindWithFilter[T any](ctx context.Context, params *QueryParam) *ObjectManager[T]
func NewCustomQuery ¶
func (*ObjectManager[T]) ExecuteListQuery ¶
func (q *ObjectManager[T]) ExecuteListQuery(instance *sql.DB) ([]T, error)
func (*ObjectManager[T]) ExecutePagedQuery ¶
func (q *ObjectManager[T]) ExecutePagedQuery(instance *sql.DB) (*Page[T], error)
func (*ObjectManager[T]) ExecuteUniqueResultQuery ¶
func (q *ObjectManager[T]) ExecuteUniqueResultQuery(instance *sql.DB) (*T, error)
func (*ObjectManager[T]) List ¶
func (q *ObjectManager[T]) List() ([]T, error)
func (*ObjectManager[T]) PagedList ¶
func (q *ObjectManager[T]) PagedList() (*Page[T], error)
func (*ObjectManager[T]) UniqueResult ¶
func (q *ObjectManager[T]) UniqueResult() (*T, error)
func (*ObjectManager[T]) WithCache ¶
func (q *ObjectManager[T]) WithCache(cache *Cache[T]) *ObjectManager[T]
func (*ObjectManager[T]) WithPage ¶
func (q *ObjectManager[T]) WithPage(page *PageRequest) *ObjectManager[T]
type PageRequest ¶
func NewPageRequest ¶
func NewPageRequest(page uint16, limit uint16, order []Sort) *PageRequest
func NewPageRequestFilter ¶
func NewPageRequestFilter(filter *Filters) *PageRequest
func (*PageRequest) GetOrder ¶
func (p *PageRequest) GetOrder() string
type PoolConfig ¶
func DefaultPoolConfig ¶
func DefaultPoolConfig() *PoolConfig
type QueryMapping ¶
type QueryMapping struct { AllowedFields []FieldMapping AllowedSortingFields map[string]string Operators map[string]string LogicalOperators map[string]string }
func (*QueryMapping) Validate ¶
func (qm *QueryMapping) Validate(items *Filters) error
type QueryParam ¶
func NewQueryBuild ¶
func NewQueryBuild(query string, filter *Filters) *QueryParam
type Sort ¶
type Sort struct { Field string `json:"field"` Direction SortDirection `json:"direction"` }
func NewSort ¶
func NewSort(field string, direction SortDirection) Sort
type SortDirection ¶
type SortDirection string
const ( ASC SortDirection = "ASC" DESC SortDirection = "DESC" )
type StringValue ¶
type StringValue string // string
type Transaction ¶
type Transaction interface {
Execute(ctx context.Context, fn func(ctx context.Context) error) error
}
func NewTransaction ¶
func NewTransaction(isolation ...sql.IsolationLevel) Transaction
Click to show internal directories.
Click to hide internal directories.