Class: Query

Defined in: src/query.coffee

Constant Summary

JOIN_STYLES =
['INNER', 'OUTER']
BIO_FORMATS =
['gff3', 'fasta', 'bed']
NULL_OPS =
['IS NULL', 'IS NOT NULL']
ATTRIBUTE_VALUE_OPS =
["=", "!=", ">", ">=", "<", "<=", "CONTAINS", "LIKE", "NOT LIKE"]
MULTIVALUE_OPS =
['ONE OF', 'NONE OF']
TERNARY_OPS =
['LOOKUP']
LOOP_OPS =
['=', '!=']
LIST_OPS =
['IN', 'NOT IN']
OP_DICT =
{
  '=': '=',
  '==': '==',
  'eq': '=',
  'eqq': '==',
  '!=': '!=',
  'ne': '!=',
  '>': '>',
  'gt': '>',
  '>=': '>=',
  'ge': '>=',
  '<': '<',
  'lt': '<',
  '<=': '<=',
  'le': '<=',
  'contains': 'CONTAINS',
  'CONTAINS': 'CONTAINS',
  'does not contain': 'DOES NOT CONTAIN',
  'DOES NOT CONTAIN': 'DOES NOT CONTAIN',
  'like': 'LIKE',
  'LIKE': 'LIKE',
  'not like': 'NOT LIKE',
  'NOT LIKE': 'NOT LIKE',
  'lookup': 'LOOKUP',
  'IS NULL': 'IS NULL',
  'is null': 'IS NULL',
  'IS NOT NULL': 'IS NOT NULL',
  'is not null': 'IS NOT NULL',
  'ONE OF': 'ONE OF',
  'one of': 'ONE OF',
  'NONE OF': 'NONE OF',
  'none of': 'NONE OF',
  'in': 'IN',
  'not in': 'NOT IN',
  'IN': 'IN',
  'NOT IN': 'NOT IN',
  'WITHIN': 'WITHIN',
  'within': 'WITHIN',
  'OVERLAPS': 'OVERLAPS',
  'overlaps': 'OVERLAPS',
  'DOES NOT OVERLAP': 'DOES NOT OVERLAP',
  'does not overlap': 'DOES NOT OVERLAP',
  'OUTSIDE': 'OUTSIDE',
  'outside': 'OUTSIDE',
  'ISA': 'ISA',
  'isa': 'ISA'
}

Class Method Summary

Instance Method Summary

Class Method Details

+ (Object) fromXML(xml)

Load the first query found in the XML.

             to `new Query(json)`.

Parameters:

  • The (String) serialised PathQuery XML

Throws:

  • (?) — Error if there is no query in the XML, or if XML is invalid.

Returns:

  • (Object) — The JSON representation of the Query, suitable for passing

Constructor Details

- (void) constructor(properties, service, undefined = {})

Construct a new Query object from a set of properties.

All options are optional. Alternative names permitted are separated by bars.

    to be used for given paths.
    when expanding `*` paths.
    paths to use to determine the sort-order.

Parameters:

  • properties (Object) The options that define the query.
  • The (Service) service this query belongs to.

Options Hash: (properties):

  • aliases|displayNames (Object<String, String>) Display names
  • model (Model) The model this query is over.
  • summaryFields (Object<String, Array<String>>) The fields to use
  • root|from (String) The root of the query (eg. Gene).
  • size|limit|maxRows (Number) The maximum number of rows to return.
  • start|offset (Number) The index of the first row to return.
  • views|view|select (Array<String>) The columns to return as output.
  • constraints|where (Array<Constraint>, Object) The constraints.
  • joins|join (Array<String>, Array<Join>) The outer-joins.
  • sortOrder|orderBy (Array<String>, Array<SortOrderElement>) The
  • constraintLogic (String) The constraint logic.

Instance Method Details

- (Query) on(events, callback, context)

Bind a callback to an event.

An implementation of the EventEmitter API, allowing clients to subscribe to events on Querys.

Parameters:

  • events (String) A space separated set of events to subscribe to.
  • callback (Function) The event-handler.
  • context (Object) The context to bind as this for the callback (optional).

Returns:

  • (Query) — This query, for chaining.

- (void) bind(args...)

alias for #on

- (Query) off()
- (Query) off(events)
- (Query) off(events, handler)
- (Query) off(events, handler, context)

Remove a particular event handler, or a more general collection.

Overloads:

- (Query) off()

Unbinds all event handlers.

Returns:

  • (Query) — this query, for chaining.

- (Query) off(events)

Unbinds all event handlers for the given events.

Parameters:

  • events (String) A space separated set of event names.

Returns:

  • (Query) — this query, for chaining.

- (Query) off(events, handler)

Unbinds the given handler for the given events.

Parameters:

  • events (String) A space separated set of event names.
  • handler (Function) The event handler to unbind.

Returns:

  • (Query) — this query, for chaining.

- (Query) off(events, handler, context)

Unbinds the given handler from all the given events where is it is bound with the given context.

Parameters:

  • events (String) A space separated set of event names.
  • handler (Function) The event handler to unbind.
  • context (Object) The this for the handler.

Returns:

  • (Query) — this query, for chaining.

- (void) unbind(args...)

alias for #off

- (Query) once(events, callback, context)

Bind an event to be executed once, and then unbound.

Parameters:

  • events (String) A space separated set of event names.
  • callback (Function) The event handler.
  • context (Object) The this for the event handler.

Returns:

  • (Query) — this query, for chaining.

See also:

- (void) emit(args...)

Alias for #trigger

- (Query) trigger(events, rest...)

Trigger a given set of events.

Parameters:

  • events (String) A space separated set of event names.
  • args (Array<Object>) The arguments to send to the handlers.

Returns:

  • (Query) — this query, for chaining.

- (Query) removeFromSelect(unwanted = [])

Remove the given paths from the select list.

   list of selected columns.

Parameters:

  • The (Array<String>, Array<PathInfo>, String, PathInfo) paths to remove from the

Returns:

  • (Query) — This query, for chaining.

- (void) removeConstraint(con, silent = false)

- (void) addToSelect(views = [])

Add an element to the select list.

- (void) select(views) (bound)

Replace the existing select list with the one passed as an argument.

- (void) adjustPath(path) (bound)

Interpret an argument as resolve the canonical path it refers to. For example, if the root of this query is known, then this method will check that the path has the same root, and add it if it is absent.

- (void) getPossiblePaths(depth = 3)

- (void) getPathInfo(path)

- (void) getSubclasses()

- (void) getType(path)

Get the type of a path.

- (void) getViewNodes()

Get all the nodes present in the view. A node is defined as the PathInfo object representing the class or reference that the attributes selected in the view belong to.

- (void) isInView(path)

Check to see whether a path is in the view. This method responds correctly whether the argument is a full path string, a headless path string, or a PathInfo object. If the path represents an attribute path then it is a simple index look up of the view. If the argument represents a reference path, then this method returns true if any of the views descends from that path.

- (?) isConstrained(path, includeAttrs = false)

Check to see whether a path is constrained to a value. If the includeAttrs parameter is true, then this method will return true if any of the attributes of the class referenced by this path are constrained to a value. Type constraints are not considered in this analysis.

Parameters:

  • path (String|PathInfo) The path to check.
  • includeAttrs (boolean) Whether to include attributes.

Returns:

  • (?) — Whether or not this path is constrained.

- (void) canHaveMultipleValues(path)

Return true is the path passed as an argument could possibly represent multiple values (this is true when any of the nodes that the path descends from represents a collection of values.

- (void) getQueryNodes()

Get all the nodes present to the query, whether they are in the views, or the constraints.

- (void) isInQuery(p)

- (void) isRelevant(path)

- (void) expandStar(path) (bound)

Interpret a path that might end in '' or '*' as the set of default paths it represent.

- (void) isOuterJoin(p)

- (void) hasView(v)

- (Promise<Number>) count(cont)

Get a promise to yield a count.

Parameters:

  • cont (Function<Number>) An optional callback.

Returns:

  • (Promise<Number>) — A promise to yield a number representing the number of rows.

- (void) appendToList(target, cb)

Add the results of this query to a list on the server.

@returns [Promise] A promise to yield the updated list information.

Parameters:

  • target (String|List) The list to add results to.

- (Query) selectPreservingImpliedConstraints(paths = [])

Get a clone of this query with the given paths selected.

The clone may have constraints added to it to preserve the implied constraints that result from the default inner-join status of paths.

We ensure we aren't changing the query by removing implicit join constraints; these implicit constraints are replaced with explicit constraints. This only works with joins on objects that have ids; you will have to handle simple objects yourself.

Parameters:

  • paths (Array) The paths to select.

Returns:

  • (Query) — The query with the altered select list.

- (Query) makeListQuery()

Get a clone of this query that can be used for list operations.

A suitable query will have a single item in its select list, and that will refer to an object id. The cloned query is guaranteed to not include elements that would otherwise be excluded by implied inner joins on deleted view paths.

Returns:

  • (Query) — The valid list query.

- (void) saveAsList(options, cb)

- (Promise<Array<Object>, Object>) summarise(path, limit, cont)

Get a summary for a single column in the results.

A summary consists of rows of summary information, and a statistics object, which always includes a uniqueValues property, which is the number of different values in the column.

Parameters:

  • path (String|PathInfo) The column to summarise.
  • limit (Number) The maximum number of rows to return.
  • cont (Function) An optional callback

Returns:

  • (Promise<Array<Object>, Object>) — A promise to return a summary.

- (Promise<Array<Object>, Object>) summarize(args...)

Get a summary for a single column in the results.

A summary consists of rows of summary information, and a statistics object, which always includes a uniqueValues property, which is the number of different values in the column.

Parameters:

  • path (String|PathInfo) The column to summarise.
  • limit (Number) The maximum number of rows to return.
  • cont (Function) An optional callback

Returns:

  • (Promise<Array<Object>, Object>) — A promise to return a summary.

- (Promise<Array<Object>, Object>) filterSummary(path, term, limit, cont = (function() {}))

Get a summary for a single column in the results, filtered by a given value.

A summary consists of rows of summary information, and a statistics object, which always includes a uniqueValues property, which is the number of different values in the column.

This method also allows the caller to have the server return only items which match the given filter.

Parameters:

  • path (String|PathInfo) The column to summarise.
  • term (String) The term to filter by.
  • limit (Number) The maximum number of rows to return.
  • cont (Function) An optional callback

Returns:

  • (Promise<Array<Object>, Object>) — A promise to return a summary.

- (Query) clone(cloneEvents)

Get an unconnected, deep clone of this query.

Any changes to the clone will not affect the original query.

                         will also be cloned.

Parameters:

  • cloneEvents (Boolean) If true, the events for the original query

Returns:

  • (Query) — A clone of this query.

- (Query) next()

Get the query for the next page of results.

Returns:

  • (Query) — A query for the next logical page of results.

- (Query) previous()

Get the query for the previous page of results.

Returns:

  • (Query) — A query for the previous logical page of results.

- (void) getSortDirection(sorted)

- (void) isOuterJoined(path)

- (void) getOuterJoin(path)

- (void) _parse_sort_order(input)

- (void) addOrSetSortOrder(so)

- (void) addSortOrder(so)

- (void) orderBy(oes)

- (void) addJoins(joins)

- (void) addJoin(join)

- (void) setJoinStyle(path, style = 'OUTER')

- (void) addConstraints(constraints)

- (void) addConstraint(constraint) (bound)

- (void) getSorting()

- (void) getConstraintXML()

- (void) getJoinXML()

- (void) toXML()

- (void) toJSON()

- (void) fetchCode(lang, cb)

- (void) setName(name)

- (void) save(name, cb)

Save a query to the server, overwriting any query of the same name.

- (void) store(name, cb)

Store this query for the first time, avoiding name collisions.

- (void) saveAsTemplate(name, cb)

- (void) getCodeURI(lang)

- (void) getExportURI(format = 'tab', options = {})

- (Boolean) needsAuthentication()

Return true if this query will require user authentication to run correctly.

This currently means that this method returns true if the query:

  • Contains any LIST constraints.

Returns:

  • (Boolean) — Whether this query needs authentication.

- (Promise<int>) fetchQID(cb)

Get a query id for referencing this query in subsequent requests.

Note that this id represents a snapshot of the query at the time of the request. Any changes to the query should require a new id to be fetched.

Duplicate queries posted to the same service will receive the same id back. So go wild*

[* do not really go wild]

Parameters:

  • cb (->) An optional callback function.

Returns:

  • (Promise<int>) — A promise to yield an id.

- (void) __bio_req(types, n)

- (void) _fasta_req()

- (void) _gff3_req()