default export

queryFor

returns instanceof Query


params
  • collectionName : string
    • a string representing a collection type on the server, e.g. 'users', 'groups', 'posts', expressed in pluralized form.
  • id : int | _.identity

    • optional » If an integer is provided, the URL produced by Query.fn.toString will represent a request to that specific resource. Otherwise, the URL will represent a request for the entire collection.
returns

instanceof Query:

methods
Query.fn.include : (CollectionName:string || CollectionName:array) -> instanceof Query

Query.fn.exclude : (CollectionName:string || CollectionName:array) -> instanceof Query

Query.fn.filter : (CollectionName:string) -> instanceof FilteredQuery (proxies Query)

Query.fn.sort : (properyName:string) -> instanceof Query

Query.fn.perPage : (n:integer) -> instanceof Query

Query.fn.page : (n:integer) -> instanceof Query

Query.fn.toString: () -> string
description

queryFor is a factory function that takes two arguments. First, a name of the primary collection for which you want to send a request, for instance: users, posts, comments, groups, etc. Second, it takes an optional integer argument that, if specified, will cause the eventually-produced string to represent a request for a specific resource of that type, for instance: users/1, posts/42, and so on. queryFor returns an instance of a class with several useful methods to construct a string, listed above.

For any of the above methods that take a collectionName as a string or an array of strings, the resulting behavior is illustrated by the following output examples. The include, exclude, _and _sort methods all share this common string-building behavior with respect to their arguments:

No nesting:

queryFor('users').include('foo.', 'bar.', 'baz.').toString()

=> /users?include[]=foo.&include[]=bar.&include=baz.

Single-level nesting

queryFor('users').include('foo.', ['bar.', 'baz.']).toString()

=> /users?include[]=foo&include[]=foo.bar&include[]=foo.baz

n-level nesting

queryFor('users').include('foo.', ['bar.', ['baz.']]).toString()

=> /users?include[]=foo&include[]=foo.bar&include[]=foo.bar.baz

Here are some examples of varying complexity.


Using filters

Notice in the type definitions at the top of this document that using filter in the method chain of a Query object returns a FilteredQuery1 . Since FilteredQuery extends Query , it has access to all of the Query methods, which still return Query instances. Instances of FilteredQuery have the following methods, which come directly from DREST's set of possible filter operations:

  • in
  • any
  • all
  • icontains
  • contains
  • startswith
  • istartswith
  • endswith
  • iendswith
  • year
  • month
  • day
  • week_day
  • regex
  • range
  • gt
  • lt
  • gte
  • lte
  • isnull
  • eq
  • is
1. FilteredQuery is not an actual class that you can get a reference to. It is implemented with a proxy object under the hood.

results matching ""

    No results matching ""