query

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

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 4 Imported by: 0

README

smartquery

Golang library for making consistent queries against structured data easier

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchAll

func MatchAll(matches []Matcher) (bool, error)

Helper function for when the user is creating a custom query type. Create all the Match objects, dump them in a slice, then use MatchAll.

Types

type FieldQuery

type FieldQuery[T comparable] struct {
	// contains filtered or unexported fields
}

func Always

func Always[T comparable]() FieldQuery[T]

func Any

func Any[T comparable](match T) FieldQuery[T]

func Exact

func Exact[T comparable](match T) FieldQuery[T]

func Like

func Like[T comparable](match T) FieldQuery[T]

func NewQuery

func NewQuery[T comparable, O optional.Optional[T]](matchType MatchType, value O) FieldQuery[T]

func None

func None[T comparable](match T) FieldQuery[T]

func (FieldQuery[T]) AsRef

func (q FieldQuery[T]) AsRef() *FieldQuery[T]

func (*FieldQuery[T]) Matches

func (q *FieldQuery[T]) Matches(value T) (bool, error)

func (*FieldQuery[T]) MatchesOption

func (q *FieldQuery[T]) MatchesOption(value optional.Optional[T]) (bool, error)

type Match

type Match[T comparable] struct {
	// contains filtered or unexported fields
}

func (Match[T]) Match

func (m Match[T]) Match() (bool, error)

type MatchType

type MatchType int
const (
	// Matching operations defined. These are currently implemented for individual values, but could be extended to slices
	// of values as noted:
	MatchAlways MatchType = iota // This ALWAYS matches. It is true if S = S ∪ S which is always true.
	MatchNone                    // True if ⦰ = S
	MatchAny                     // True if ⦰ != S
	MatchSome                    // True if ⦰ != S1 ∩ S2. TODO: implement this! Until we support slices in queries this is the same as Exact though...
	MatchExact                   // True if ⦰ = S1 𝚫 S2
	MatchLike                    // Only valid for strings: perform
)

type Matcher

type Matcher interface {
	Match() (bool, error)
}

func NewMatch

func NewMatch[T comparable](operand optional.Optional[T], query Query[T]) Matcher

func NewValueMatch

func NewValueMatch[T comparable](operand T, query Query[T]) Matcher

type Query

type Query[T comparable] interface {
	Matches(T) (bool, error)
	MatchesOption(optional.Optional[T]) (bool, error)
}

type StringQuery

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

func AlwaysString

func AlwaysString() StringQuery

func AnyString

func AnyString(match string) StringQuery

func ExactString

func ExactString(match string) StringQuery

func LikeString

func LikeString(match string) StringQuery

func NewStringQuery

func NewStringQuery(matchType MatchType, value optional.Optional[string]) StringQuery

func NoneString

func NoneString(match string) StringQuery

func (StringQuery) AsRef

func (q StringQuery) AsRef() *StringQuery

func (*StringQuery) Matches

func (q *StringQuery) Matches(value string) (bool, error)

func (*StringQuery) MatchesOption

func (q *StringQuery) MatchesOption(value optional.Optional[string]) (bool, error)

Jump to

Keyboard shortcuts

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