Documentation ¶
Index ¶
- Variables
- func ColumnNotFound(tableName, columnName string) error
- func IsNoRows(e error) bool
- func TableNotExists(table string, err ...error) error
- func TagNotFound(tableName, tagName string) error
- type Aggregator
- type AggregatorFactory
- type AggregatorFactoryFunc
- type Column
- type Context
- type GetValuer
- type Iterable
- type Iterator
- type KeyValue
- type KeyValues
- type Measurement
- type OrderedQuery
- type Query
- func From(source Table) Query
- func FromChannel(source <-chan Record) Query
- func FromIterable(source Iterable) Query
- func FromRecords(source []Record) Query
- func FromStorage(s Storage, tablename string, f func(name TableName) (bool, error), ...) (Query, error)
- func FromWithTags(source Table, tags KeyValues) Query
- func (q Query) Aggregate(ctx Context, f func(Context, Record, Record) (Record, error)) (result Record, err error)
- func (q Query) AggregateWith(names []string, aggregatorFactories []AggregatorFactory) Query
- func (q Query) AggregateWithFunc(ctx Context, names []string, aggregators []Aggregator) (result Record, err error)
- func (q Query) AggregateWithSeed(ctx Context, seed Record, f func(Context, Record, Record) (Record, error)) (result Record, err error)
- func (q Query) AggregateWithSeedBy(ctx Context, seed Record, f func(Context, Record, Record) (Record, error), ...) (result Record, err error)
- func (q Query) All(ctx Context, predicate func(Record) bool) (bool, error)
- func (q Query) Any(ctx Context) (bool, error)
- func (q Query) AnyWith(ctx Context, predicate func(Record) bool) (bool, error)
- func (q Query) Append(item Record) Query
- func (q Query) Concat(q2 Query) Query
- func (q Query) Count(ctx Context) (r int, err error)
- func (q Query) CountWith(ctx Context, predicate func(Record) bool) (r int, err error)
- func (q Query) DefaultIfEmpty(defaultValue Record) Query
- func (q Query) Distinct() Query
- func (q Query) DistinctBy(selector func(Record) Value) Query
- func (q Query) Except(q2 Query) Query
- func (q Query) ExceptBy(q2 Query, selector func(Record) Value) Query
- func (q Query) First(ctx Context) (Record, bool, error)
- func (q Query) FirstWith(ctx Context, predicate func(Record) bool) (Record, bool, error)
- func (q Query) ForEach(ctx Context, action func(int, Record) error) error
- func (q Query) FullJoin(inner Query, resultSelector func(outer Record, inner Record) Record) Query
- func (q Query) GroupJoin(inner Query, outerKeySelector func(Record) Value, ...) Query
- func (q Query) IndexOf(ctx Context, predicate func(Record) bool) (int, error)
- func (q Query) Intersect(q2 Query) Query
- func (q Query) IntersectBy(q2 Query, selector func(Record) Value) Query
- func (q Query) Join(isLeft bool, inner Query, outerKeySelector func(Record) (Value, error), ...) Query
- func (q Query) Last(ctx Context) (r Record, exists bool, err error)
- func (q Query) LastWith(ctx Context, predicate func(Record) bool) (r Record, exists bool, err error)
- func (q Query) Map(mapFunc func(Context, Record) (Record, error)) Query
- func (q Query) OrderByAscending(selector func(Record) (Value, error)) OrderedQuery
- func (q Query) OrderByDescending(selector func(Record) (Value, error)) OrderedQuery
- func (q Query) Prepend(item Record) Query
- func (q Query) Results(ctx Context) (r []Record, err error)
- func (q Query) Reverse() Query
- func (q Query) Select(selector func(int, Record) (Record, error)) Query
- func (q Query) SequenceEqual(ctx Context, q2 Query) (bool, error)
- func (q Query) Single(ctx Context) (Record, bool, error)
- func (q Query) SingleWith(ctx Context, predicate func(Record) bool) (r Record, found bool, err error)
- func (q Query) Skip(count int) Query
- func (q Query) SkipWhile(predicate func(int, Record) bool) Query
- func (q Query) Sort(less func(i, j Record) bool) Query
- func (q Query) Take(count int) Query
- func (q Query) TakeWhile(predicate func(int, Record) bool) Query
- func (q Query) ToReference() *ReferenceQuery
- func (q Query) Union(q2 Query) Query
- func (q Query) UnionAll(q2 Query) Query
- func (q Query) Where(predicate func(int, Record) (bool, error)) Query
- func (q Query) Zip(q2 Query, resultSelector func(Record, Record) Record) Query
- type Record
- type RecordSet
- type ReferenceQuery
- type Stash
- type Storage
- type Table
- type TableAlias
- type TableName
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrNoRows = sql.ErrNoRows
var ErrNotFound = records.ErrNotFound
var ErrReadFirst = errors.New("read first while fetch items")
var Wrap = errors.Wrap
Functions ¶
func ColumnNotFound ¶
func TableNotExists ¶
func TagNotFound ¶
Types ¶
type Aggregator ¶
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 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 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 ¶
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 ¶
FromChannel initializes a linq query with passed channel, linq iterates over channel until it is closed.
func FromIterable ¶
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 ¶
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 FromWithTags ¶
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 (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) AnyWith ¶
AnyWith determines whether any element of a collection satisfies a condition.
func (Query) Append ¶
Append inserts an item to the end of a collection, so it becomes the last item.
func (Query) Concat ¶
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) CountWith ¶
CountWith returns a number that represents how many elements in the specified collection satisfy a condition.
func (Query) DefaultIfEmpty ¶
DefaultIfEmpty returns the elements of the specified sequence if the sequence is empty.
func (Query) Distinct ¶
Distinct method returns distinct elements from a collection. The result is an unordered collection that contains no duplicate values.
func (Query) DistinctBy ¶
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 ¶
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 ¶
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) FirstWith ¶
FirstWith returns the first element of a collection that satisfies a specified condition.
func (Query) ForEach ¶
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) 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 ¶
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 ¶
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 ¶
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) 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) 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 ¶
Prepend inserts an item to the beginning of a collection, so it becomes the first item.
func (Query) Reverse ¶
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 ¶
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 ¶
SequenceEqual determines whether two collections are equal.
func (Query) Single ¶
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 ¶
Skip bypasses a specified number of elements in a collection and then returns the remaining elements.
func (Query) SkipWhile ¶
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 ¶
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 ¶
Take returns a specified number of contiguous elements from the start of a collection.
func (Query) TakeWhile ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ReferenceQuery ¶
type TableAlias ¶
type TableAlias = records.TableAlias