memcore

package
v0.0.0-...-c9c7940 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = sql.ErrNoRows
View Source
var ErrNotFound = records.ErrNotFound
View Source
var ErrReadFirst = errors.New("read first while fetch items")
View Source
var Wrap = errors.Wrap

Functions

func ColumnNotFound

func ColumnNotFound(tableName, columnName string) error

func IsNoRows

func IsNoRows(e error) bool

func TableNotExists

func TableNotExists(table string, err ...error) error

func TagNotFound

func TagNotFound(tableName, tagName string) error

Types

type Aggregator

type Aggregator interface {
	Agg(Context, Record) error

	Result(Context) (Value, error)
}

type AggregatorFactory

type AggregatorFactory interface {
	Create() Aggregator
}

type AggregatorFactoryFunc

type AggregatorFactoryFunc func() Aggregator

func AggregatorFunc

func AggregatorFunc(create func() vm.Aggregator,
	readValue func(Context, Record) (Value, error)) AggregatorFactoryFunc

func (AggregatorFactoryFunc) Create

func (f AggregatorFactoryFunc) Create() Aggregator

type Column

type Column = records.Column

type Context

type Context = interface{}

type GetValuer

type GetValuer = vm.GetValuer

type Iterable

type Iterable interface {
	Iterate() Iterator
}

Iterable is an interface that has to be implemented by a custom collection in order to work with linq.

type Iterator

type Iterator func(Context) (item Record, err error)

Iterator is an alias for function to iterate over data.

type KeyValue

type KeyValue = records.KeyValue

func MapToTags

func MapToTags(tags map[string]string) []KeyValue

type KeyValues

type KeyValues = records.KeyValues

type Measurement

type Measurement = records.Measurement

type OrderedQuery

type OrderedQuery struct {
	Query
	// contains filtered or unexported fields
}

OrderedQuery is the type returned from OrderByAscending, OrderByDescending ThenByAscending and ThenByDescending functions.

func (OrderedQuery) Distinct

func (oq OrderedQuery) Distinct() OrderedQuery

Distinct method returns distinct elements from a collection. The result is an ordered collection that contains no duplicate values.

NOTE: Distinct method on OrderedQuery type has better performance than Distinct method on Query type.

func (OrderedQuery) ThenByAscending

func (oq OrderedQuery) ThenByAscending(selector func(Record) (Value, error)) OrderedQuery

ThenByAscending performs a subsequent ordering of the elements in a collection in ascending order. This method enables you to specify multiple sort criteria by applying any number of ThenByAscending or ThenByDescending methods.

func (OrderedQuery) ThenByDescending

func (oq OrderedQuery) ThenByDescending(selector func(Record) (Value, error)) OrderedQuery

ThenByDescending performs a subsequent ordering of the elements in a collection in descending order. This method enables you to specify multiple sort criteria by applying any number of ThenBy or ThenByDescending methods.

type Query

type Query struct {
	Iterate func() Iterator
}

Query is the type returned from query functions. It can be iterated manually as shown in the example.

func From

func From(source Table) Query

From initializes a linq query with passed slice, array or map as the source. String, channel or struct implementing Iterable interface can be used as an input. In this case From delegates it to FromString, FromChannel and FromIterable internally.

func FromChannel

func FromChannel(source <-chan Record) Query

FromChannel initializes a linq query with passed channel, linq iterates over channel until it is closed.

func FromIterable

func FromIterable(source Iterable) Query

FromIterable initializes a linq query with custom collection passed. This collection has to implement Iterable interface, linq iterates over items, that has to implement Comparable interface or be basic types.

func FromRecords

func FromRecords(source []Record) Query

From initializes a linq query with passed slice, array or map as the source. String, channel or struct implementing Iterable interface can be used as an input. In this case From delegates it to FromString, FromChannel and FromIterable internally.

func FromStorage

func FromStorage(s Storage, tablename string, f func(name TableName) (bool, error), trace func(TableName)) (Query, error)

func FromWithTags

func FromWithTags(source Table, tags KeyValues) Query

func (Query) Aggregate

func (q Query) Aggregate(ctx Context, f func(Context, Record, Record) (Record, error)) (result Record, err error)

Aggregate applies an accumulator function over a sequence.

Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling f() one time for each element in source except the first one. Each time f() is called, Aggregate passes both the element from the sequence and an aggregated value (as the first argument to f()). The first element of source is used as the initial aggregate value. The result of f() replaces the previous aggregated value.

Aggregate returns the final result of f().

func (Query) AggregateWith

func (q Query) AggregateWith(names []string, aggregatorFactories []AggregatorFactory) Query

func (Query) AggregateWithFunc

func (q Query) AggregateWithFunc(ctx Context, names []string, aggregators []Aggregator) (result Record, err error)

func (Query) AggregateWithSeed

func (q Query) AggregateWithSeed(ctx Context, seed Record,
	f func(Context, Record, Record) (Record, error)) (result Record, err error)

AggregateWithSeed applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling f() one time for each element in source except the first one. Each time f() is called, Aggregate passes both the element from the sequence and an aggregated value (as the first argument to f()). The value of the seed parameter is used as the initial aggregate value. The result of f() replaces the previous aggregated value.

Aggregate returns the final result of f().

func (Query) AggregateWithSeedBy

func (q Query) AggregateWithSeedBy(ctx Context, seed Record,
	f func(Context, Record, Record) (Record, error),
	resultSelector func(Context, Record) (Record, error)) (result Record, err error)

AggregateWithSeedBy applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling f() one time for each element in source. Each time func is called, Aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). The value of the seed parameter is used as the initial aggregate value. The result of func replaces the previous aggregated value.

The final result of func is passed to resultSelector to obtain the final result of Aggregate.

func (Query) All

func (q Query) All(ctx Context, predicate func(Record) bool) (bool, error)

All determines whether all elements of a collection satisfy a condition.

func (Query) Any

func (q Query) Any(ctx Context) (bool, error)

Any determines whether any element of a collection exists.

func (Query) AnyWith

func (q Query) AnyWith(ctx Context, predicate func(Record) bool) (bool, error)

AnyWith determines whether any element of a collection satisfies a condition.

func (Query) Append

func (q Query) Append(item Record) Query

Append inserts an item to the end of a collection, so it becomes the last item.

func (Query) Concat

func (q Query) Concat(q2 Query) Query

Concat concatenates two collections.

The Concat method differs from the Union method because the Concat method returns all the original elements in the input sequences. The Union method returns only unique elements.

func (Query) Count

func (q Query) Count(ctx Context) (r int, err error)

Count returns the number of elements in a collection.

func (Query) CountWith

func (q Query) CountWith(ctx Context, predicate func(Record) bool) (r int, err error)

CountWith returns a number that represents how many elements in the specified collection satisfy a condition.

func (Query) DefaultIfEmpty

func (q Query) DefaultIfEmpty(defaultValue Record) Query

DefaultIfEmpty returns the elements of the specified sequence if the sequence is empty.

func (Query) Distinct

func (q Query) Distinct() Query

Distinct method returns distinct elements from a collection. The result is an unordered collection that contains no duplicate values.

func (Query) DistinctBy

func (q Query) DistinctBy(selector func(Record) Value) Query

DistinctBy method returns distinct elements from a collection. This method executes selector function for each element to determine a value to compare. The result is an unordered collection that contains no duplicate values.

func (Query) Except

func (q Query) Except(q2 Query) Query

Except produces the set difference of two sequences. The set difference is the members of the first sequence that don't appear in the second sequence.

func (Query) ExceptBy

func (q Query) ExceptBy(q2 Query,
	selector func(Record) Value) Query

ExceptBy invokes a transform function on each element of a collection and produces the set difference of two sequences. The set difference is the members of the first sequence that don't appear in the second sequence.

func (Query) First

func (q Query) First(ctx Context) (Record, bool, error)

First returns the first element of a collection.

func (Query) FirstWith

func (q Query) FirstWith(ctx Context, predicate func(Record) bool) (Record, bool, error)

FirstWith returns the first element of a collection that satisfies a specified condition.

func (Query) ForEach

func (q Query) ForEach(ctx Context, action func(int, Record) error) error

ForEach performs the specified action on each element of a collection.

The first argument to action represents the zero-based index of that element in the source collection. This can be useful if the elements are in a known order and you want to do something with an element at a particular index, for example. It can also be useful if you want to retrieve the index of one or more elements. The second argument to action represents the element to process.

func (Query) FullJoin

func (q Query) FullJoin(inner Query, resultSelector func(outer Record, inner Record) Record) Query

func (Query) GroupJoin

func (q Query) GroupJoin(inner Query,
	outerKeySelector func(Record) Value,
	innerKeySelector func(Record) Value,
	resultSelector func(outer Record, inners []Record) Record) Query

GroupJoin correlates the elements of two collections based on key equality, and groups the results.

This method produces hierarchical results, which means that elements from outer query are paired with collections of matching elements from inner. GroupJoin enables you to base your results on a whole set of matches for each element of outer query.

The resultSelector function is called only one time for each outer element together with a collection of all the inner elements that match the outer element. This differs from the Join method, in which the result selector function is invoked on pairs that contain one element from outer and one element from inner.

GroupJoin preserves the order of the elements of outer, and for each element of outer, the order of the matching elements from inner.

func (Query) IndexOf

func (q Query) IndexOf(ctx Context, predicate func(Record) bool) (int, error)

IndexOf searches for an element that matches the conditions defined by a specified predicate and returns the zero-based index of the first occurrence within the collection. This method returns -1 if an item that matches the conditions is not found.

func (Query) Intersect

func (q Query) Intersect(q2 Query) Query

Intersect produces the set intersection of the source collection and the provided input collection. The intersection of two sets A and B is defined as the set that contains all the elements of A that also appear in B, but no other elements.

func (Query) IntersectBy

func (q Query) IntersectBy(q2 Query,
	selector func(Record) Value) Query

IntersectBy produces the set intersection of the source collection and the provided input collection. The intersection of two sets A and B is defined as the set that contains all the elements of A that also appear in B, but no other elements.

IntersectBy invokes a transform function on each element of both collections.

func (Query) Join

func (q Query) Join(isLeft bool, inner Query,
	outerKeySelector func(Record) (Value, error),
	innerKeySelector func(Record) (Value, error),
	resultSelector func(outer Record, inner Record) Record) Query

Join correlates the elements of two collection based on matching keys.

A join refers to the operation of correlating the elements of two sources of information based on a common key. Join brings the two information sources and the keys by which they are matched together in one method call. This differs from the use of SelectMany, which requires more than one method call to perform the same operation.

Join preserves the order of the elements of outer collection, and for each of these elements, the order of the matching elements of inner.

func (Query) Last

func (q Query) Last(ctx Context) (r Record, exists bool, err error)

Last returns the last element of a collection.

func (Query) LastWith

func (q Query) LastWith(ctx Context, predicate func(Record) bool) (r Record, exists bool, err error)

LastWith returns the last element of a collection that satisfies a specified condition.

func (Query) Map

func (q Query) Map(mapFunc func(Context, Record) (Record, error)) Query

func (Query) OrderByAscending

func (q Query) OrderByAscending(selector func(Record) (Value, error)) OrderedQuery

OrderByAscending sorts the elements of a collection in ascending order. Elements are sorted according to a key.

func (Query) OrderByDescending

func (q Query) OrderByDescending(selector func(Record) (Value, error)) OrderedQuery

OrderByDescending sorts the elements of a collection in descending order. Elements are sorted according to a key.

func (Query) Prepend

func (q Query) Prepend(item Record) Query

Prepend inserts an item to the beginning of a collection, so it becomes the first item.

func (Query) Results

func (q Query) Results(ctx Context) (r []Record, err error)

Results iterates over a collection and returnes slice of interfaces

func (Query) Reverse

func (q Query) Reverse() Query

Reverse inverts the order of the elements in a collection.

Unlike OrderBy, this sorting method does not consider the actual values themselves in determining the order. Rather, it just returns the elements in the reverse order from which they are produced by the underlying source.

func (Query) Select

func (q Query) Select(selector func(int, Record) (Record, error)) Query

Select projects each element of a collection into a new form by incorporating the element's index. Returns a query with the result of invoking the transform function on each element of original source.

The first argument to selector represents the zero-based index of that element in the source collection. This can be useful if the elements are in a known order and you want to do something with an element at a particular index, for example. It can also be useful if you want to retrieve the index of one or more elements. The second argument to selector represents the element to process.

This projection method requires the transform function, selector, to produce one value for each value in the source collection. If selector returns a value that is itself a collection, it is up to the consumer to traverse the subcollections manually. In such a situation, it might be better for your query to return a single coalesced collection of values. To achieve this, use the SelectMany method instead of Select. Although SelectMany works similarly to Select, it differs in that the transform function returns a collection that is then expanded by SelectMany before it is returned.

func (Query) SequenceEqual

func (q Query) SequenceEqual(ctx Context, q2 Query) (bool, error)

SequenceEqual determines whether two collections are equal.

func (Query) Single

func (q Query) Single(ctx Context) (Record, bool, error)

Single returns the only element of a collection, and nil if there is not exactly one element in the collection.

func (Query) SingleWith

func (q Query) SingleWith(ctx Context, predicate func(Record) bool) (r Record, found bool, err error)

SingleWith returns the only element of a collection that satisfies a specified condition, and nil if more than one such element exists.

func (Query) Skip

func (q Query) Skip(count int) Query

Skip bypasses a specified number of elements in a collection and then returns the remaining elements.

func (Query) SkipWhile

func (q Query) SkipWhile(predicate func(int, Record) bool) Query

SkipWhile bypasses elements in a collection as long as a specified condition is true and then returns the remaining elements. The element's index is used in the logic of the predicate function.

This method tests each element by using predicate and skips the element if the result is true. After the predicate function returns false for an element, that element and the remaining elements in source are returned and there are no more invocations of predicate.

func (Query) Sort

func (q Query) Sort(less func(i, j Record) bool) Query

Sort returns a new query by sorting elements with provided less function in ascending order. The comparer function should return true if the parameter i is less than j. While this method is uglier than chaining OrderBy, OrderByDescending, ThenBy and ThenByDescending methods, it's performance is much better.

func (Query) Take

func (q Query) Take(count int) Query

Take returns a specified number of contiguous elements from the start of a collection.

func (Query) TakeWhile

func (q Query) TakeWhile(predicate func(int, Record) bool) Query

TakeWhile returns elements from a collection as long as a specified condition is true. The element's index is used in the logic of the predicate function. The first argument of predicate represents the zero-based index of the element within collection. The second argument represents the element to test.

func (Query) ToReference

func (q Query) ToReference() *ReferenceQuery

func (Query) Union

func (q Query) Union(q2 Query) Query

Union produces the set union of two collections.

This method excludes duplicates from the return set. This is different behavior to the Concat method, which returns all the elements in the input collection including duplicates.

func (Query) UnionAll

func (q Query) UnionAll(q2 Query) Query

UnionAll concatenates two collections.

The UnionAll method differs from the Union method because the UnionAll method returns all the original elements in the input sequences. The Union method returns only unique elements.

func (Query) Where

func (q Query) Where(predicate func(int, Record) (bool, error)) Query

Where filters a collection of values based on a predicate. Each element's index is used in the logic of the predicate function.

The first argument represents the zero-based index of the element within collection. The second argument of predicate represents the element to test.

func (Query) Zip

func (q Query) Zip(q2 Query,
	resultSelector func(Record, Record) Record) Query

Zip applies a specified function to the corresponding elements of two collections, producing a collection of the results.

The method steps through the two input collections, applying function resultSelector to corresponding elements of the two collections. The method returns a collection of the values that are returned by resultSelector. If the input collections do not have the same number of elements, the method combines elements until it reaches the end of one of the collections. For example, if one collection has three elements and the other one has four, the result collection has only three elements.

type Record

type Record = records.Record

func MergeRecord

func MergeRecord(outerAs string, outer Record, innerAs string, inner Record) Record

func SortByColumnName

func SortByColumnName(r Record) Record

type RecordSet

type RecordSet = records.RecordSet

type ReferenceQuery

type ReferenceQuery struct {
	Query
	IsCopy bool
	// contains filtered or unexported fields
}

type Stash

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

func (*Stash) Get

func (stash *Stash) Get(ctx Context, index int) (item Record, err error)

func (*Stash) ReadAll

func (stash *Stash) ReadAll(ctx Context, next Iterator) error

type Storage

type Storage = records.Storage

func NewStorage

func NewStorage() Storage

type Table

type Table = records.Table

func ToTable

func ToTable(values []map[string]interface{}) (Table, error)

type TableAlias

type TableAlias = records.TableAlias

type TableName

type TableName = records.TableName

type Value

type Value = records.Value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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