Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ResultSet<T>

ResultSet class allowing chainable queries. Intended to be instanced internally. Collection.find(), Collection.where(), and Collection.chain() instantiate this.

example

mycollection.chain() .find({ 'doors' : 4 }) .where(function(obj) { return obj.name === 'Toyota' }) .data();

param

the data type

param

nested properties of data type

Type parameters

  • T: any

Hierarchy

  • ResultSet

Index

Type aliases

Static ContainsHelperType

ContainsHelperType: R

Static LokiOps

LokiOps: object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object | object

Static Query

Query: object & object & object & object

Constructors

constructor

Properties

_collection

_collection: Collection<T>

_filterInitialized

_filterInitialized: boolean = false

_filteredRows

_filteredRows: number[] = []

Methods

$and

  • $and(expressionArray: Query<Doc<T>>[]): this

$or

  • $or(expressionArray: Query<Doc<T>>[]): this

compoundsort

  • compoundsort(properties: (keyof T | Object)[]): this
  • Allows sorting a ResultSet based on multiple columns.

    example

    // to sort by age and then name (both ascending) rs.compoundsort(['age', 'name']); // to sort by age (ascending) and then by name (descending) rs.compoundsort(['age', ['name', true]);

    Parameters

    • properties: (keyof T | Object)[]

      array of property names or subarray of [propertyname, isdesc] used evaluate sort order

    Returns this

    Reference to this ResultSet, sorted, for future chain operations.

copy

  • To support reuse of ResultSet in branched query situations.

    Returns ResultSet<T>

    Returns a copy of the ResultSet (set) but the underlying document references will be the same.

count

  • count(): number
  • Returns the number of documents in the ResultSet.

    Returns number

    The number of documents in the ResultSet.

data

  • Terminates the chain and returns array of filtered documents

    Parameters

    Returns Doc<T>[]

    Array of documents in the ResultSet

eqJoin

  • Left joining two sets of data. Join keys can be defined or calculated properties eqJoin expects the right join key values to be unique. Otherwise left data will be joined on the last joinData object with that key

    Parameters

    • joinData: Collection<any> | ResultSet<any> | any[]

      Data array to join to.

    • leftJoinKey: string | function

      Property name in this result set to join on or a function to produce a value to join on

    • rightJoinKey: string | function

      Property name in the joinData to join on or a function to produce a value to join on

    • Optional mapFun: function
        • (left: any, right: any): any
        • Parameters

          • left: any
          • right: any

          Returns any

    • Optional dataOptions: DataOptions

    Returns ResultSet<any>

    A ResultSet with data in the format [{left: leftObj, right: rightObj}]

find

  • find(query?: Query<Doc<T>>, firstOnly?: boolean): this
  • Used for querying via a mongo-style query object.

    Parameters

    • Optional query: Query<Doc<T>>

      A mongo-style query object used for filtering current results.

    • Default value firstOnly: boolean = false

      (Optional) Used by collection.findOne() - flag if this was invoked via findOne()

    Returns this

    this ResultSet for further chain ops.

findAnd

  • findAnd(expressionArray: Query<Doc<T>>[]): this
  • Oversee the operation of AND'ed query expressions. AND'ed expression evaluation runs each expression progressively against the full collection, internally utilizing existing chained ResultSet functionality. Only the first filter can utilize a binary index.

    Parameters

    • expressionArray: Query<Doc<T>>[]

      array of expressions

    Returns this

    this ResultSet for further chain ops.

findOr

  • findOr(expressionArray: Query<Doc<T>>[]): this
  • Oversee the operation of OR'ed query expressions. OR'ed expression evaluation runs each expression individually against the full collection, and finally does a set OR on each expression's results. Each evaluation can utilize a binary index to prevent multiple linear array scans.

    Parameters

    • expressionArray: Query<Doc<T>>[]

      array of expressions

    Returns this

    this ResultSet for further chain ops.

getScoring

  • getScoring(): Scorer.ScoreResult[]

limit

  • limit(qty: number): this
  • Allows you to limit the number of documents passed to next chain operation. A ResultSet copy() is made to avoid altering original ResultSet.

    Parameters

    • qty: number

      The number of documents to return.

    Returns this

    Returns a copy of the ResultSet, limited by qty, for subsequent chain ops.

map

  • Applies a map function into a new collection for further chaining.

    Type parameters

    • U: any

    Parameters

    • mapFun: function

      javascript map function

        • (obj: Doc<T>, index: number, array: Doc<T>[]): U
        • Parameters

          • obj: Doc<T>
          • index: number
          • array: Doc<T>[]

          Returns U

    • Optional dataOptions: DataOptions

    Returns ResultSet<U>

mapReduce

  • mapReduce<U1, U2>(mapFunction: function, reduceFunction: function): U2
  • data transformation via user supplied functions

    Type parameters

    • U1

    • U2

    Parameters

    • mapFunction: function

      this function accepts a single document for you to transform and return

        • (item: Doc<T>, index: number, array: Doc<T>[]): U1
        • Parameters

          • item: Doc<T>
          • index: number
          • array: Doc<T>[]

          Returns U1

    • reduceFunction: function

      this function accepts many (array of map outputs) and returns single value

        • (array: U1[]): U2
        • Parameters

          • array: U1[]

          Returns U2

    Returns U2

    The output of your reduceFunction

offset

  • offset(pos: number): this
  • Used for skipping 'pos' number of documents in the ResultSet.

    Parameters

    • pos: number

      Number of documents to skip; all preceding documents are filtered out.

    Returns this

    Returns a copy of the ResultSet, containing docs starting at 'pos' for subsequent chain ops.

remove

  • remove(): this
  • Removes all document objects which are currently in ResultSet from collection (as well as ResultSet)

    Returns this

    this (empty) ResultSet for further chain ops.

reset

  • reset(): this
  • Reset the ResultSet to its initial state.

    Returns this

    Reference to this ResultSet, for future chain operations.

simplesort

  • Simpler, loose evaluation for user to sort based on a property name. (chainable). Sorting based on the same lt/gt helper functions used for binary indices.

    Parameters

    • propname: keyof T

      name of property to sort by.

    • Default value options: boolean | SimpleSortOptions = { desc: false }

      boolean for sort descending or options object

    Returns this

    Reference to this ResultSet, sorted, for future chain operations.

sort

  • sort(comparefun: function): this
  • User supplied compare function is provided two documents to compare. (chainable)

    example

    rslt.sort(function(obj1, obj2) { if (obj1.name === obj2.name) return 0; if (obj1.name > obj2.name) return 1; if (obj1.name < obj2.name) return -1; });

    Parameters

    • comparefun: function

      A javascript compare function used for sorting.

        • (a: Doc<T>, b: Doc<T>): number
        • Parameters

          Returns number

    Returns this

    Reference to this ResultSet, sorted, for future chain operations.

sortByScoring

  • sortByScoring(ascending?: boolean): this
  • Sorts the ResultSet based on the last full-text-search scoring.

    Parameters

    • Default value ascending: boolean = false

    Returns this

toJSON

transform

  • transform(transform: string | Transform<T>[], parameters?: object): this
  • Executes a named collection transform or raw array of transform steps against the ResultSet.

    Parameters

    • transform: string | Transform<T>[]

      name of collection transform or raw transform array

    • Optional parameters: object

    Returns this

    either (this) ResultSet or a clone of of this ResultSet (depending on steps)

update

  • update(updateFunction: function): this
  • Used to run an update operation on all documents currently in the ResultSet.

    Parameters

    • updateFunction: function

      User supplied updateFunction(obj) will be executed for each document object.

        • Parameters

          Returns Doc<T>

    Returns this

    this ResultSet for further chain ops.

where

  • where(fun: function): this
  • Used for filtering via a javascript filter function.

    Parameters

    • fun: function

      A javascript function used for filtering current results by.

        • (obj: Doc<T>): boolean
        • Parameters

          Returns boolean

    Returns this

    this ResultSet for further chain ops.

Generated using TypeDoc