ParseQuery

Class ParseQuery - Handles querying data from Parse.

author

Fosco Marotto [email protected]

package

Parse

Methods

Create a Parse Query for a given Parse Class.

__construct(mixed $className) 

Arguments

$className

mixed

Class Name of data on Parse.

Add constraint that at all of the passed in queries matches.

_and(array $queries) : \Parse\ParseQuery

Arguments

$queries

array

The list of queries to OR.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Returns an associative array of the query constraints.

_getOptions() : array

Response

array

All queries must have same class name.

_matchClassname(array $queryObjects) : string
static
Throws
\Exception

If all queries don't have same class.

Arguments

$queryObjects

array

Array of ParseQuery objects.

Response

string

class name.

Combines queries for NOR, AND, OR queries.

_mergeQueries(string $key, array $queries) : \Parse\ParseQuery

Arguments

$key

string

The condition $and, $or, $nor.

$queries

array

The list of queries to combine.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add constraint that at none of the passed in queries matches.

_nor(array $queries) : \Parse\ParseQuery

Arguments

$queries

array

The list of queries to NOR.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add constraint that at least one of the passed in queries matches.

_or(array $queries) : \Parse\ParseQuery

Arguments

$queries

array

The list of queries to OR.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Sets the conditions of this parse query from an array

_setConditions(array $conditions) 
Throws
\Parse\ParseException

Arguments

$conditions

array

Array of Conditions to set

Set the query orderBy to ascending for the given key(s). It can also add secondary sort descriptors without overwriting the existing order.

addAscending(mixed $key) : \Parse\ParseQuery

Arguments

$key

mixed

Key(s) to sort by, which is a string or an array of strings.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Helper for condition queries.

addCondition(string $key, string $condition, mixed $value) 
Throws
\Exception

Arguments

$key

string

The key to where constraints

$condition

string

The condition name

$value

mixed

The condition value, can be a string or an array of strings

Set the query orderBy to descending for a given key(s). It can also add secondary sort descriptors without overwriting the existing order.

addDescending(mixed $key) : \Parse\ParseQuery

Arguments

$key

mixed

Key(s) to sort by, which is a string or an array of strings.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Execute an aggregate query and returns aggregate results.

aggregate(array $pipeline) : array

Arguments

$pipeline

array

stages to process query

Response

array

Constructs a ParseQuery object that is the AND of the passed in queries objects.

andQueries(array $queryObjects) : \Parse\ParseQuery
static

All queries must have same class name.

Throws
\Exception

If all queries don't have same class.

Arguments

$queryObjects

array

Array of ParseQuery objects to AND.

Response

\Parse\ParseQuery

The query that is the AND of the passed in queries.

Set the query orderBy to ascending for the given key(s). It overwrites the existing order criteria.

ascending(mixed $key) : \Parse\ParseQuery

Arguments

$key

mixed

Key(s) to sort by, which is a string or an array of strings.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Build query string from query constraints.

buildQueryString(array $queryOptions) : string

Arguments

$queryOptions

array

Associative array of the query constraints.

Response

string

Query string.

Adds a constraint to the query that requires a particular key's value to be contained by the provided list of values. Get objects where all array elements match.

containedBy(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The values that will match.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be contained in the provided list of values.

containedIn(string $key, array $values) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$values

array

The values that will match.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Adds a constraint for finding string values that contain a provided string. This may be slow for large datasets.

contains(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The substring that the value must contain.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to contain each one of the provided list of values.

containsAll(string $key, array $values) : \Parse\ParseQuery

Arguments

$key

string

The key to check. This key's value must be an array.

$values

array

The values that will match.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to contain each one of the provided list of values starting with the given string.

containsAllStartingWith(string $key, array $values) : \Parse\ParseQuery

Arguments

$key

string

The key to check. This key's value must be an array.

$values

array

The values that will match as starting string.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Execute a count query and return the count.

count(boolean $useMasterKey = false) : integer

Arguments

$useMasterKey

boolean

If the query should use the master key

Response

integer

Set the query orderBy to descending for a given key(s). It overwrites the existing order criteria.

descending(mixed $key) : \Parse\ParseQuery

Arguments

$key

mixed

Key(s) to sort by, which is a string or an array of strings.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Execute a distinct query and return unique values.

distinct(string $key) : array

Arguments

$key

string

field to find distinct values

Response

array

Add a constraint for finding objects that not contain the given key.

doesNotExist(string $key) : \Parse\ParseQuery

Arguments

$key

string

The key that should not exist.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint that requires that a key's value not match a value in an object returned by the given query.

doesNotMatchKeyInQuery(string $key, string $queryKey, \Parse\ParseQuery $query) : \Parse\ParseQuery

Arguments

$key

string

The key that contains teh value that is being excluded.

$queryKey

string

The key in objects returned by the query to match against.

$query

\Parse\ParseQuery

The query to run.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint that requires that a key's value not matches a ParseQuery constraint.

doesNotMatchQuery(string $key, \Parse\ParseQuery $query) : \Parse\ParseQuery

Arguments

$key

string

The key that the contains the object not to match the query.

$query

\Parse\ParseQuery

The query that should not match.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Iterates over each result of a query, calling a callback for each one. The items are processed in an unspecified order. The query may not have any sort order, and may not use limit or skip.

each(callable $callback, boolean $useMasterKey = false, integer $batchSize = 100) 
Throws
\Exception

If query has sort, skip, or limit.

Arguments

$callback

callable

Callback that will be called with each result of the query.

$useMasterKey

boolean

$batchSize

integer

Add a constraint to the query that requires a particular key's value to end with the provided value.

endsWith(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The substring that the value must end with.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Set a constraint for a field matching a given value.

equalTo(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

Key to set up an equals constraint.

$value

mixed

Value the key must equal.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Restricts the fields of the returned Parse.Objects to all keys except the provided keys. Exclude takes precedence over select and include.

excludeKey(mixed $key) : \Parse\ParseQuery

(Requires Parse Server 3.6.0+)

Arguments

$key

mixed

The name(s) of the key(s) to exclude. It could be string, or an Array of string.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint for finding objects that contain the given key.

exists(string $key) : \Parse\ParseQuery

Arguments

$key

string

The key that should exist.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Execute a find query and return the results.

find(boolean $useMasterKey = false, boolean $decodeObjects = true) : array<mixed,\Parse\ParseObject>

Arguments

$useMasterKey

boolean

$decodeObjects

boolean

If set to false, will return raw data instead of ParseObject instances

Response

array<mixed,\Parse\ParseObject>

Execute a query to get only the first result.

first(boolean $useMasterKey = false, boolean $decodeObjects = true) : array|\Parse\ParseObject

Arguments

$useMasterKey

boolean

If the query should use the master key

$decodeObjects

boolean

If set to false, will return raw data instead of ParseObject instances

Response

array|\Parse\ParseObject

Returns the first object or an empty array

Adds a constraint for finding string values that contain a provided string using Full Text Search

fullText(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The substring that the value must contain.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Execute a query to retrieve a specific object.

get(string $objectId, boolean $useMasterKey = false) : array|\Parse\ParseObject
Throws
\Parse\ParseException

Arguments

$objectId

string

Unique object id to retrieve.

$useMasterKey

boolean

If the query should use the master key

Response

array|\Parse\ParseObject

Returns the selected object or an empty array

Add a constraint to the query that requires a particular key's value to be greater than the provided value.

greaterThan(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The value that provides an Lower bound.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be greater than or equal to the provided value.

greaterThanOrEqualTo(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The value that provides a lower bound.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be greater than or equal to the provided relative time string.

greaterThanOrEqualToRelativeTime(string $key, string $relativeTime) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$relativeTime

string

The relative time that provides a lower bound

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be greater than the provided relative time string.

greaterThanRelativeTime(string $key, string $relativeTime) : \Parse\ParseQuery

Arguments

$key

string

The key to check

$relativeTime

string

The relative time that provides a lower bound

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Handles result from ParseClient::_request

handleQueryResult(array $result, boolean $decodeObjects) : Array

Arguments

$result

array

Array of ParseObject raw data.

$decodeObjects

boolean

If set to false, will return raw data instead of ParseObject instances

Response

Array

Array of ParseObjects or raw data.

Includes all nested Parse.Objects.

includeAllKeys() : \Parse\ParseQuery

Requires Parse Server 3.0.0+

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Include nested Parse Objects for the provided key. You can use dot notation to specify which fields in the included object are also fetch.

includeKey(mixed $key) : \Parse\ParseQuery

You can include all nested Parse Objects by passing in '*'. (Requires Parse Server 3.0.0+)

Arguments

$key

mixed

The name(s) of the key(s) to include. It could be string, or an Array of string.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be less than the provided value.

lessThan(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The value that provides an Upper bound.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be less than or equal to the provided value.

lessThanOrEqualTo(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The value that provides an upper bound.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be less than or equal to the provided date string.

lessThanOrEqualToRelativeTime(string $key, string $relativeTime) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$relativeTime

string

The relative time that provides an upper bound

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be less than the provided relative time string.

lessThanRelativeTime(string $key, string $relativeTime) : \Parse\ParseQuery

Arguments

$key

string

The key to check

$relativeTime

string

The relative time that provides an upper bound

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Set the limit parameter as a query constraint.

limit(integer $n) : \Parse\ParseQuery

Arguments

$n

integer

Number of objects to return from the query.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Adds a regular expression constraint for finding string values that match the provided regular expression.

matches(string $key, string $regex, string $modifiers = '') : \Parse\ParseQuery

This may be slow for large datasets.

Arguments

$key

string

The key that the string to match is stored in.

$regex

string

The regular expression pattern to match.

$modifiers

string

Modifies the search, supports i, m

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint that requires that a key's value matches a value in an object returned by the given query.

matchesKeyInQuery(string $key, string $queryKey, \Parse\ParseQuery $query) : \Parse\ParseQuery

Arguments

$key

string

The key that contains the value that is being matched.

$queryKey

string

The key in objects returned by the query to match against.

$query

\Parse\ParseQuery

The query to run.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint that requires that a key's value matches a ParseQuery constraint.

matchesQuery(string $key, \Parse\ParseQuery $query) : \Parse\ParseQuery

Arguments

$key

string

The key that the contains the object to match the query.

$query

\Parse\ParseQuery

The query that should match.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a proximity based constraint for finding objects with key point values near the point given.

near(string $key, \Parse\ParseGeoPoint $point) : \Parse\ParseQuery

Arguments

$key

string

The key that the ParseGeoPoint is stored in.

$point

\Parse\ParseGeoPoint

The reference ParseGeoPoint that is used.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Constructs a ParseQuery object that is the NOR of the passed in queries objects.

norQueries(array $queryObjects) : \Parse\ParseQuery
static

All queries must have same class name.

Throws
\Exception

If all queries don't have same class.

Arguments

$queryObjects

array

Array of ParseQuery objects to NOR.

Response

\Parse\ParseQuery

The query that is the NOR of the passed in queries.

Add a constraint to the query that requires a particular key's value to not be contained in the provided list of values.

notContainedIn(string $key, array $values) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$values

array

The values that will not match.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to be not equal to the provided value.

notEqualTo(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The value that must not be equalled.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Constructs a ParseQuery object that is the OR of the passed in queries objects.

orQueries(array $queryObjects) : \Parse\ParseQuery
static

All queries must have same class name.

Throws
\Exception

If all queries don't have same class.

Arguments

$queryObjects

array

Array of ParseQuery objects to OR.

Response

\Parse\ParseQuery

The query that is the OR of the passed in queries.

Add a constraint to the query that requires a particular key's coordinates that contains a ParseGeoPoint

polygonContains(string $key, \Parse\ParseGeoPoint $point) : \Parse\ParseQuery

Arguments

$key

string

The key of the ParsePolygon

$point

\Parse\ParseGeoPoint

The point that will be contained.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Converts a string into a regex that matches it.

quote(mixed $s) : string

Surrounding with \Q .. \E does this, we just need to escape \E's in the text separately.

Arguments

$s

mixed

The string or array being replaced.

Response

string

Returns the string converted.

Changes the read preference that the backend will use when performing the query to the database.

readPreference(string $readPreference, string $includeReadPreference = null, string $subqueryReadPreference = null) : \Parse\ParseQuery

Arguments

$readPreference

string

The read preference for the main query.

$includeReadPreference

string

The read preference for the queries to include pointers.

$subqueryReadPreference

string

The read preference for the sub queries.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Converts a string into a regex that matches it at the beginning

regexStartWith(mixed $s) : string

Arguments

$s

mixed

The string or array being replaced.

Response

string

Returns the string converted.

Add constraint for parse relation.

relatedTo(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

$value

mixed

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Restrict the fields of the returned Parse Objects to include only the provided keys. If this is called multiple times, then all of the keys specified in each of the calls will be included.

select(mixed $key) : \Parse\ParseQuery

Arguments

$key

mixed

The name(s) of the key(s) to include. It could be string, or an Array of string.

Response

\Parse\ParseQuery

Returns the query, so you can chain this call.

Set the skip parameter as a query constraint.

skip(integer $n) : \Parse\ParseQuery

Arguments

$n

integer

Number of objects to skip from start of results.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's value to start with the provided value.

startsWith(string $key, mixed $value) : \Parse\ParseQuery

Arguments

$key

string

The key to check.

$value

mixed

The substring that the value must start with.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

The response will include the total number of objects satisfying this query, dispite limit / skip. Might be useful for pagination.

withCount(boolean $includeCount = true) : \Parse\ParseQuery

Note: the results will be an object results: holding {ParseObject} array and count: integer holding total number

Arguments

$includeCount

boolean

If response should include count, true by default.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's coordinates be contained within a given rectangular geographic bounding box.

withinGeoBox(string $key, \Parse\ParseGeoPoint $southwest, \Parse\ParseGeoPoint $northeast) : \Parse\ParseQuery

Arguments

$key

string

The key of the ParseGeoPoint

$southwest

\Parse\ParseGeoPoint

The lower-left corner of the box.

$northeast

\Parse\ParseGeoPoint

The upper-right corner of the box.

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.

withinKilometers(string $key, \Parse\ParseGeoPoint $point, integer $maxDistance, boolean $sort = true) : \Parse\ParseQuery

Radius of earth used is 6371.0 kilometers.

Arguments

$key

string

The key of the ParseGeoPoint

$point

\Parse\ParseGeoPoint

The ParseGeoPoint that is used.

$maxDistance

integer

Maximum distance (in kilometers)

$sort

boolean

Return objects sorted by distance

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.

withinMiles(string $key, \Parse\ParseGeoPoint $point, integer $maxDistance, boolean $sort = true) : \Parse\ParseQuery

Radius of earth used is 3958.8 miles.

Arguments

$key

string

The key of the ParseGeoPoint

$point

\Parse\ParseGeoPoint

The ParseGeoPoint that is used.

$maxDistance

integer

Maximum distance (in miles)

$sort

boolean

Return objects sorted by distance

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a constraint to the query that requires a particular key's coordinates be contained within and on the bounds of a given polygon Supports closed and open (last point is connected to first) paths

withinPolygon(string $key, array $points) : \Parse\ParseQuery

Polygon must have at least 3 points

Arguments

$key

string

The key of the ParseGeoPoint

$points

array

Array of ParseGeoPoint

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.

withinRadians(string $key, \Parse\ParseGeoPoint $point, integer $maxDistance, boolean $sort = true) : \Parse\ParseQuery

Arguments

$key

string

The key of the ParseGeoPoint

$point

\Parse\ParseGeoPoint

The ParseGeoPoint that is used.

$maxDistance

integer

Maximum distance (in radians)

$sort

boolean

Return objects sorted by distance

Response

\Parse\ParseQuery

Returns this query, so you can chain this call.

Properties

Class name for data stored on Parse.

className : string
var

Type(s)

string

Where constraints.

where : array
var

Type(s)

array

Order By keys.

orderBy : array
var

Type(s)

array

Include nested objects.

includes : array
var

Type(s)

array

Exclude keys.

excludes : array
var

Type(s)

array

Include certain keys only.

selectedKeys : array
var

Type(s)

array

Skip from the beginning of the search results.

skip : integer
var

Type(s)

integer

Determines if the query is a count query or a results query.

count : integer
var

Type(s)

integer

Limit of results, defaults to 100 when not explicitly set.

limit : integer
var

Type(s)

integer

The read preference for the main query.

readPreference : string
var

Type(s)

string

The read preference for the queries to include pointers.

includeReadPreference : string
var

Type(s)

string

The read preference for the sub queries.

subqueryReadPreference : string
var

Type(s)

string