Documentation
¶
Index ¶
- type Adaptor
- func (vr Adaptor[T]) Delete(ctx context.Context, id string) error
- func (vr Adaptor[T]) Get(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, ...) (io.ReadCloser, error)
- func (vr Adaptor[T]) GetById(ctx context.Context, id string) (io.ReadCloser, error)
- func (vr Adaptor[T]) Post(ctx context.Context, r io.Reader) (io.ReadCloser, error)
- func (vr Adaptor[T]) Put(ctx context.Context, id string, r io.Reader) error
- type DbType
- type EditableModel
- type Executor
- type FilterSet
- type IntDbType
- type JsonDbType
- type Limiter
- type Model
- type Querier
- type QueryError
- type Resource
- type SQLResource
- func (r SQLResource[T, P]) Count(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, ...) (uint64, error)
- func (r SQLResource[T, P]) Delete(ctx context.Context, id string) error
- func (r SQLResource[T, P]) Get(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, ...) ([]T, error)
- func (r SQLResource[T, P]) GetById(ctx context.Context, id string) (t T, err error)
- func (r SQLResource[T, P]) Post(ctx context.Context, t T) (string, error)
- func (r SQLResource[T, P]) Put(ctx context.Context, id string, t T) error
- type Statement
- type StringDbType
- type TimeDbType
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adaptor ¶
Adaptor matches store.Resource to crud.Resource
func (Adaptor[T]) Get ¶
func (vr Adaptor[T]) Get(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, innerOp crud.InnerOperation, sort []string, ascending bool, offset, limit int, count bool) (io.ReadCloser, error)
Get resource list
type DbType ¶
type DbType interface {
Where(field string, op crud.Operator, val string) (string, interface{}, error)
}
DBType represents a database column type that can be filtered
type EditableModel ¶
type EditableModel interface {
PrepareCreate() ([]string, error)
PrepareUpdate(id string) ([]string, error)
}
EditableModel is a pointer to a Model, that allows modifications
type Executor ¶
type Executor interface {
Begin(ctx context.Context) (Transaction, error)
}
Executor is an interface used by Post, Put and Delete
type Querier ¶
type Querier interface {
GetContext(ctx context.Context, result interface{}, query string, args ...interface{}) error
SelectContext(ctx context.Context, result interface{}, query string, args ...interface{}) error
}
Querier is the interface used by GetById and Get
type QueryError ¶
QueryError encapsulates error in oracle Query
func (QueryError) Error ¶
func (err QueryError) Error() string
func (QueryError) Unwrap ¶
func (err QueryError) Unwrap() error
type Resource ¶
type Resource[T any] interface { // Get resource by id GetById(context.Context, string) (T, error) // Get resource by filter Get(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, innerOp crud.InnerOperation, sort []string, ascending bool, offset, limit int) ([]T, error) // Count resource by filter Count(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, innerOp crud.InnerOperation) (uint64, error) // Post (create) new resource, return id Post(ctx context.Context, data T) (string, error) // Put (update) resource Put(ctx context.Context, id string, data T) error // Delete resource by id Delete(context.Context, string) error }
Resource implements the CRUD operations
type SQLResource ¶
type SQLResource[T Model, P interface { *T EditableModel }] struct { // contains filtered or unexported fields }
SQLResource manages database operations in a givem table
func New ¶
func New[T Model, P interface { *T EditableModel }](querier Querier, exec Executor, tableName string, columns map[string]DbType, limiter Limiter) SQLResource[T, P]
New creates a Resource for the given table
func (SQLResource[T, P]) Count ¶
func (r SQLResource[T, P]) Count(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, innerOp crud.InnerOperation) (uint64, error)
Count filtered resources
func (SQLResource[T, P]) Delete ¶
func (r SQLResource[T, P]) Delete(ctx context.Context, id string) error
Delete a resource from the database
func (SQLResource[T, P]) Get ¶
func (r SQLResource[T, P]) Get(ctx context.Context, filter []crud.Filter, outerOp crud.OuterOperation, innerOp crud.InnerOperation, sort []string, ascending bool, offset, limit int) ([]T, error)
Get filtered (and possibly paginated) resources
func (SQLResource[T, P]) GetById ¶
func (r SQLResource[T, P]) GetById(ctx context.Context, id string) (t T, err error)
GetById searches the table for the given id