repository

package module
v0.0.0-...-ea1cc3c Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 4 Imported by: 3

README

repository

Golang repository pattern

This package looks to expose the repository pattern pattern using golang generics and interfaces. Implementations of these patterns can be found in the impl directory, and are independently released from the core interfaces, using go multi-module repositories. Repository interface is inspired by gorm mixed with some appengine datastore for strongly typed queries.

This repository (pun intended) is under ACTIVE DEVELOPMENT... ANYTHING CAN BREAK... ANYTIME!!! Use at your own risk, or create an issue to ask for a 1.0 release.

Implementations

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New(`repository: not implemented`)
	ErrNotFound       = errors.New(`repository: not found`)
	ErrDone           = errors.New(`repository: iterator has no more results`)
)

Functions

This section is empty.

Types

type BinaryCondition

type BinaryCondition[T any, V comparable] struct {
	Field    string
	Operator Operator
	Value    V
	Accessor func(T) V
}

binaryCondition defines binary operator as Specification It is used for =, >, <, >=, <= operators.

func (BinaryCondition[T, V]) Match

func (s BinaryCondition[T, V]) Match(t T) bool

func (BinaryCondition[T, V]) String

func (s BinaryCondition[T, V]) String() string

type Condition

type Condition[T any] interface {
	String() string
	Match(T) bool
}

func And

func And[T any](conditions ...Condition[T]) Condition[T]

func Equal

func Equal[T any, V comparable](field string, value V, accessor func(T) V) Condition[T]

Not delivers = operator as Specification

func Not

func Not[T any](condition Condition[T]) Condition[T]

type FuncCondition

type FuncCondition[T any] func(T) bool

func (FuncCondition[T]) Match

func (fn FuncCondition[T]) Match(t T) bool

func (FuncCondition[T]) String

func (fn FuncCondition[T]) String() string

type Iterator

type Iterator[T any] interface {
	Next() (*T, error)
}

type JoinCondition

type JoinCondition[T any] struct {
	Conditions []Condition[T]
	Separator  Operator
}

func (JoinCondition[T]) Match

func (join JoinCondition[T]) Match(t T) bool

func (JoinCondition[T]) String

func (join JoinCondition[T]) String() string

type NotCondition

type NotCondition[T any] struct {
	Condition Condition[T]
}

func (NotCondition[T]) Match

func (not NotCondition[T]) Match(t T) bool

func (NotCondition[T]) String

func (not NotCondition[T]) String() string

type Operator

type Operator uint8
const (

	// join operators
	AND Operator
	OR

	// binary operators
	EQUAL
	GREATER
	LESS
	GREATEROREQUAL
	LESSOREQUAL
)

func (Operator) String

func (join Operator) String() string

type Query

type Query interface {
}

type Repository

type Repository[T any] interface {

	// Create constructs + stores obj T.
	// If any identifiers are created as part of the insert, they are mutated on the incomming argument.
	Create(ctx context.Context, obj ...T) error

	// Get returns a single item matching a set of conditions
	Get(ctx context.Context, cond Condition[T]) (T, error)

	// List
	List(ctx context.Context, cond Condition[T]) Iterator[T]

	// Update
	Update(ctx context.Context, obj ...T) error

	// Delete
	Delete(ctx context.Context, obj ...T) error
}

Directories

Path Synopsis
impl
gorm module
memory module
sqlstruct module

Jump to

Keyboard shortcuts

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