Overview

Namespaces

  • LeanCloud
    • Engine
    • Operation
    • Storage
    • Uploader

Classes

  • ACL
  • AppRouter
  • Bytes
  • Client
  • File
  • GeoPoint
  • LeanObject
  • MIMEType
  • Push
  • Query
  • Region
  • Relation
  • Role
  • RouteCache
  • SaveOption
  • SMS
  • User

Exceptions

  • BatchRequestError
  • CloudException
  • Overview
  • Namespace
  • Class

Class Query

Query representation for finding objects on LeanCloud

Namespace: LeanCloud
Located at LeanCloud/Query.php
Methods summary
public
# __construct( string $queryClass )

Initilize query

Initilize query

Parameters

$queryClass
The class to operate on
public string
# getClassName( )

Get className of the query

Get className of the query

Returns

string
public LeanCloud\Query
# equalTo( string $key, mixed $val )

Field equals to a value

Field equals to a value

Equal-to condition is the strongest constraint overall, it has higher precedence than all other conditions. All prior conditions set on the field will be discarded and of no effect when adding an equal-to condition.

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# notEqualTo( string $key, mixed $val )

Field does not equal to a value

Field does not equal to a value

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# lessThan( string $key, mixed $val )

Field less than a value

Field less than a value

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# lessThanOrEqualTo( string $key, mixed $val )

Field less than or equal to a value

Field less than or equal to a value

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# greaterThan( string $key, mixed $val )

Field greater than a value

Field greater than a value

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# greaterThanOrEqualTo( string $key, mixed $val )

Field greater than or equal to a vaule

Field greater than or equal to a vaule

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# containedIn( string $key, array $vals )

Field value is contained in an array

Field value is contained in an array

Parameters

$key
$vals

Returns

LeanCloud\Query
public LeanCloud\Query
# notContainedIn( string $key, array $vals )

Field value is not contained in an array

Field value is not contained in an array

Parameters

$key
$vals

Returns

LeanCloud\Query
public LeanCloud\Query
# containsAll( string $key, array $vals )

Field contains all values from an array

Field contains all values from an array

Parameters

$key
$vals

Returns

LeanCloud\Query
public LeanCloud\Query
# sizeEqualTo( string $key, integer $val )

Array field size equal to val

Array field size equal to val

Parameters

$key
$val

Returns

LeanCloud\Query
public LeanCloud\Query
# exists( string $key )

Field exists

Field exists

Parameters

$key

Returns

LeanCloud\Query
public LeanCloud\Query
# notExists( string $key )

Field not exists

Field not exists

Parameters

$key

Returns

LeanCloud\Query
public LeanCloud\Query
# contains( string $key, string $val )

String field contains a (string) value

String field contains a (string) value

It performs regex search on string fields, thus might be slow for large datasets.

Parameters

$key
$val
The substring to find

Returns

LeanCloud\Query
public LeanCloud\Query
# startsWith( string $key, string $val )

String field starts with a (string) value

String field starts with a (string) value

It performs regex search on string fields, thus might be slow for large datasets.

Parameters

$key
$val
The start string

Returns

LeanCloud\Query
public LeanCloud\Query
# endsWith( string $key, string $val )

String field ends with a (string) value

String field ends with a (string) value

It performs regex search on string fields, thus might be slow for large datasets.

Parameters

$key
$val
The end string

Returns

LeanCloud\Query
public LeanCloud\Query
# matches( string $key, string $regex, string $modifiers = "" )

String field matches a regular expression

String field matches a regular expression

The regex string should not be enclosed with /, and modifiers must be provided via $modifiers argument.

It performs regex search on string fields, thus might be slow for large datasets.

Parameters

$key
$regex
The pattern string
$modifiers
(optional) Regexp modifiers: "i", "m" etc.

Returns

LeanCloud\Query
public LeanCloud\Query
# matchesInQuery( string $key, LeanCloud\Query $query )

Matches result objects returned from a sub-query

Matches result objects returned from a sub-query

Parameters

$key
$query
The sub-query

Returns

LeanCloud\Query
public LeanCloud\Query
# notMatchInQuery( string $key, LeanCloud\Query $query )

Not-match result objects returned from a sub-query

Not-match result objects returned from a sub-query

Parameters

$key
$query
The sub-query

Returns

LeanCloud\Query
public LeanCloud\Query
# matchesFieldInQuery( string $key, string $queryKey, LeanCloud\Query $query )

Matches values of specified field from a sub-query

Matches values of specified field from a sub-query

Parameters

$key
$queryKey
Target field key in sub-query
$query
The sub-query

Returns

LeanCloud\Query
public LeanCloud\Query
# notMatchFieldInQuery( string $key, string $queryKey, LeanCloud\Query $query )

Not-match values of specified field from a sub-query

Not-match values of specified field from a sub-query

Parameters

$key
$queryKey
Target field key in sub-query
$query
The sub-query

Returns

LeanCloud\Query
public LeanCloud\Query
# relatedTo( string $key, LeanCloud\LeanObject $obj )

Relation field related to an object

Relation field related to an object

Parameters

$key
A relation field key
$obj
Target object to relate

Returns

LeanCloud\Query
public LeanCloud\Query
# near( string $key, LeanCloud\GeoPoint $point )

Find objects near a geo point

Find objects near a geo point

Parameters

$key
Field key
$point
Center geo point

Returns

LeanCloud\Query
public LeanCloud\Query
# withinRadians( string $key, LeanCloud\GeoPoint $point, number $distance )

Find objects within a sphere of point, in radians

Find objects within a sphere of point, in radians

Parameters

$key
Field key
$point
Center geo point
$distance
Distance in radians

Returns

LeanCloud\Query
public LeanCloud\Query
# withinKilometers( string $key, LeanCloud\GeoPoint $point, number $distance )

Find objects within a sphere of point, in kilometers

Find objects within a sphere of point, in kilometers

Parameters

$key
Field key
$point
Center geo point
$distance
Distance in kilometers

Returns

LeanCloud\Query
public LeanCloud\Query
# withinMiles( string $key, LeanCloud\GeoPoint $point, number $distance )

Find objects within a sphere of point, in miles

Find objects within a sphere of point, in miles

Parameters

$key
Field key
$point
Center geo point
$distance
Distance in miles

Returns

LeanCloud\Query
public LeanCloud\Query
# withinBox( string $key, LeanCloud\GeoPoint $southwest, LeanCloud\GeoPoint $northeast )

Find objects within a rectangle

Find objects within a rectangle

Parameters

$key
Field key
$southwest
Geo point of southwest corner
$northeast
Geo point of northeast corner

Returns

LeanCloud\Query
public LeanCloud\Query
# select( string|array $keys )

Specify fields to include in query result

Specify fields to include in query result

It accepts either one array of keys, or variable number of keys.

Parameters

$keys
string Field keys

Returns

LeanCloud\Query
public LeanCloud\Query
# _include( string|array $keys )

Include nested objects in query result

Include nested objects in query result

Include nested object to return full object instead of pointer. It accepts an array of keys, or variable number of keys.

Deep nested fields can be specified as dot separated field, e.g. $commentQuery->include('post.author') which will include author object in comment query result.

Parameters

$keys
string Field keys

Returns

LeanCloud\Query
public LeanCloud\Query
# limit( integer $n )

Limit number of rows to return

Limit number of rows to return

The default limit is 100, with a max of 1000 results being returned at a time.

Parameters

$n
Number of rows

Returns

LeanCloud\Query
public LeanCloud\Query
# skip( integer $n )

Skip number of rows to return in the query

Skip number of rows to return in the query

The default is to skip at zero.

Parameters

$n
Number of rows to skip

Returns

LeanCloud\Query
public LeanCloud\Query
# ascend( string $key )

Set ascending order on field

Set ascending order on field

Previous order constraints will be discarded.

Parameters

$key

Returns

LeanCloud\Query
public LeanCloud\Query
# descend( string $key )

Set descending order on field

Set descending order on field

Previous order constraints will be discarded.

Parameters

$key

Returns

LeanCloud\Query
public LeanCloud\Query
# addAscend( string $key )

Add ascending order on a field

Add ascending order on a field

The previous ordering will have higher precedence over this one.

Parameters

$key

Returns

LeanCloud\Query
public LeanCloud\Query
# addDescend( string $key )

Add descending order on a field

Add descending order on a field

The previous ordering will have higher precedence over this one.

Parameters

$key

Returns

LeanCloud\Query
public static LeanCloud\Query
# orQuery( ... $queries )

Compose OR query from variable number of queries

Compose OR query from variable number of queries

It accepts one array of LeanQueries, or variable number of LeanQueries.

Parameters

$queries

Returns

LeanCloud\Query
public static LeanCloud\Query
# andQuery( ... $queries )

Compose AND query from variable number of queries

Compose AND query from variable number of queries

It accepts one array of LeanQueries, or variable number of LeanQueries.

Parameters

$queries

Returns

LeanCloud\Query
public LeanCloud\Query
# addOption( string $key, mixed $val )

Add extra option in query request

Add extra option in query request

Extra options will be appended as request params when sending query to cloud.

Parameters

$key
$val

Returns

LeanCloud\Query
public array
# encode( )

Encode query to JSON representation

Encode query to JSON representation

Returns

array
public LeanCloud\LeanObject
# get( string $objectId )

Query object by id

Query object by id

Parameters

$objectId

Returns

LeanCloud\LeanObject
public LeanCloud\LeanObject
# first( )

Find the first object by the query

Find the first object by the query

Returns

LeanCloud\LeanObject
public array
# find( integer $skip = -1, integer $limit = -1 )

Find and return objects by the query

Find and return objects by the query

The skip or limit provided here will have higher precedence than the ones specified by query's skip and limit methods. It does not mutate query.

Parameters

$skip
(optional) Number of rows to skip
$limit
(optional) Max number of rows to fetch

Returns

array
public integer
# count( )

Count number of objects by the query

Count number of objects by the query

Returns

integer
public static array
# doCloudQuery( string $cql, array $pvalues = array() )

Doing a CQL query to retrive objects

Doing a CQL query to retrive objects

It returns an array that contains:

  • className - Class name of the query
  • results - List of objects
  • count - Number of objects when it's a count query

Parameters

$cql
CQL statement
$pvalues
Positional values to replace in CQL

Returns

array

Link

https://leancloud.cn/docs/cql_guide.html
API documentation generated by ApiGen