Find objects that some arbitrary action would be performed on, given the
same request.

@param options.model
@param options.query

TODO this will be less expensive when waterline supports a caching layer
970770
function(req) {


    // handle add/remove routes that have :parentid as the primary key field
    var originalId;
    if (req.params.parentid) {
      originalId = req.params.id;
      req.params.id = req.params.parentid;
    }

    return new Promise(function(resolve, reject) {
        sails.hooks.blueprints.middleware.find(req, {
          ok: resolve,
          serverError: reject,
          // this isn't perfect, since it returns a 500 error instead of a 404 error
          // but it is better than crashing the app when a record doesn't exist
          notFound: reject
        });
      })
      .then(function(result) {
        if (originalId !== undefined) {
          req.params.id = originalId;
        }
        return result;
      });
  }
765128
public Either<String, Either<Joiner4All, Mapper4All>> query(String sqlOrJsonQuery, NamedParameters namedParams, Map<String, String> reqHeaders, boolean printToConsole, String queryMode) {
        return query(sqlOrJsonQuery, namedParams, reqHeaders, printToConsole, queryMode, false);
    }
331947
public function search($query = '', $options = null)
    {
        $this->setOptionsAndQuery($options, $query);

        $query = $this->getQuery();
        $path = $this->getPath();

        $params = $this->getOptions();

        // Send scroll_id via raw HTTP body to handle cases of very large (> 4kb) ids.
        if ('_search/scroll' == $path) {
            $data = [self::OPTION_SCROLL_ID => $params[self::OPTION_SCROLL_ID]];
            unset($params[self::OPTION_SCROLL_ID]);
        } else {
            $data = $query->toArray();
        }

        $response = $this->getClient()->request(
            $path,
            Request::GET,
            $data,
            $params
        );

        return $this->_builder->buildResultSet($response, $query);
    }
1137874
function onFetching(model, columns, options) {
        if (options.forUpdate && options.transacting) {
            options.query.forUpdate();
        }
    }
410212
def find(self, query):
        ''''''
        if self.upstream:
            return self.upstream.find(query)
        else:
            return False
1356424
function findOne(query, options, callback) {
    if (typeof options === 'function') {
      callback = options
      options = {}
    }
    self.emit('findOne', query, options)
    findByQuery(query, options, function (error, objects) {
      self.emit('received', objects[0])
      callback(undefined, objects[0])
    })
  }
240534
function Query(server, query, options, token) {
  this.server = server;
  this.query = query;
  // Used to track the presence of r.args (workaround)
  this.originalQuery = util.deepCopy(query);
  this.options = {};
  this.context = {};
  this.frames = [];
  this.nowValue = ReqlDate.now();
  this.complete = false;
  this.token = token;

}
1007191
function query (args) {
    // add session if not set
    if (!args.session) {
        args.session = this.session
    }
    // return original method call
    return this.model.query(args)
}
714201
public ResultSet executeQuery(ReadContext context, Options.QueryOption... options) {
    return context.executeQuery(this, options);
  }
521555
function doQuery(options) {
            return models.Tag.findOne(options.data, _.omit(options, ['data']))
                .then((model) => {
                    if (!model) {
                        return Promise.reject(new common.errors.NotFoundError({
                            message: common.i18n.t('errors.api.tags.tagNotFound')
                        }));
                    }

                    return {
                        tags: [urlsForTag(model.id, model.toJSON(options), options)]
                    };
                });
        }
905442
function doQuery(options) {
            return models.Webhook.getByEventAndTarget(options.data.webhooks[0].event, options.data.webhooks[0].target_url, _.omit(options, ['data']))
                .then((webhook) => {
                    if (webhook) {
                        return Promise.reject(new common.errors.ValidationError({message: common.i18n.t('errors.api.webhooks.webhookAlreadyExists')}));
                    }

                    return models.Webhook.add(options.data.webhooks[0], _.omit(options, ['data']));
                })
                .then((model) => {
                    return {
                        webhooks: [model.toJSON(options)]
                    };
                });
        }
895716
function doQuery(options) {
            return models.User.transferOwnership(options.data.owner[0], _.omit(options, ['data']))
                .then((models) => {
                    return {
                        users: models.toJSON(_.omit(options, ['data']))
                    };
                });
        }
1193907
public function findSlugForFilterData(Query $query, array $options)
    {
        if (!isset($options['request']) || get_class($options['request']) !== ServerRequest::class) {
            user_error('The request query option must exist and must be of type Cake\Http\ServerRequest.');
        }

        if (!isset($options['filterData'])) {
            user_error('No filterData option provided.');
        }

        /** @var ServerRequest $request */
        $request = $options['request'];
        $filterData = $options['filterData'];

        return $query
            ->select($this->getAlias() . '.slug')
            ->where([
                $this->getAlias() . '.controller' => $request->getParam('controller'),
                $this->getAlias() . '.action' => $request->getParam('action'),
                $this->getAlias() . '.filter_data' => $this->_encodeFilterData($filterData)
            ])
            ->where($this->_pluginCondition($request));
    }
324020
@InterfaceAudience.Private
    public List<QueryRow> query(QueryOptions options) throws CouchbaseLiteException {
        if (options == null)
            options = new QueryOptions();
        if (groupOrReduce(options))
            return viewStore.reducedQuery(options);
        else
            return viewStore.regularQuery(options);
    }
45228
def query(self, action=None):
        
        if action in self.cache:
            return self.cache[action]['query'].replace('&format=json', '')
        return self.cache.keys() or None
331731
function find(query, options, callback) {
    if (typeof options === 'function') {
      callback = options
      options = {}
    }

    self.emit('find', query, options)
    if (callback !== undefined) {
      findByQuery(query, options, function(error, data) {
        if (error) return callback(error)
        self.emit('received', data)
        callback(null, data)
      })
    } else {
      return findByQuery(query, options)
    }
  }
833724
def run_query(self, query):
        
        collection = self.ds.connection(self.collection_name)

        cursor = collection.find(query)
        if cursor.count() == 0:
            raise LookupError('Collection {0} has no {1} records'
                              .format(self.collection_name, self.model_klass.__name__))
        return [self.model_klass.from_json(entry) for entry in cursor]