personBox.all()
, you may want to filter entities by their properties. ObjectBox's query syntax should be familiar to every Swift developer, because queries are written in Swift:startsWith()
here). While most of these calls look like the regular Swift calls you're used to, they are actually provided by ObjectBox's code generator, so not all methods you would e.g. find on a String
are available for queries. See below for available operations.Query.find()
, Query.count()
, and all the other operations that execute a query multiple times. In performance-critical situations, building a new query object thousands of times can easily become costly.&&
and ||
.&& > ||
). You can use parentheses to group conditions and affect the truth condition of the whole expression. ∈
and ∉
; for example, disallowing teens entry to your disco: Person.age ∉ (10..<18)
==
and !=
, as in Person.firstName == "Steve"
<
and >
, as in CocoaPod.rating > 4.5
Property<T, String>.startsWith()
, as their names are already much more familiar to Swift developers.Query.find()
will return all results that matchQuery.count()
will return the count of all results that matchQuery.findUnique()
will return an unique match from the result set; returns nil if no result was found and throws if the result is not uniqueordered()
method:ordered(by:,flags:)
to sort in descending order, to sort case sensitively or to treat null values specially . For example, to sort the above results in descending order and case sensitively instead:find()
executions and you don't want to create a new Query object every time.setParameter()
methods. Refer to the Query API docs for a comprenhesive list of permitted setParameter()
variants.Query.setParameter()
and Query.setParameters()
method. (Note the plural s.) The first version will set the comparison value of a condition that matches to a new value. The second version does the same for comparisons with two values, hence the plural s. query.setParameter(Person.age, to: 18)
for a query you built using personBox.query { Person.age == 21 }.build()
will effectively change the condition to Person.age == 18
query.setParameters(Person.age, to: 10, and: 18)
for a query you built using personBox.query { Person.age.isBetween(0, and: 99) }.build()
will effectively change the condition to Person.age.isBetween(10, and: 18)
.=
) for this:Double
to a setter for a condition that operates on String
, for example.max
, min
, average
, count
, but also various find methods. These are available on the PropertyQuery
type, that you can get from a regular query like this:PropertyQuery
will respect all conditions of its original Query
. So in the example above, only entities with a firstName
that starts with "S" will be regarded. Use the empty block variant personBox.query()
if you want to operate on all entities.ordered(by:,flags:)
setting. If you need a fixed order for your proerty query results, you must sort them manually after retrieving them.Int
(what would you do with a non-fractional average anyway?).[25, 30, 30, 40, 40]
, you will get [25, 30, 40]
as a distinct result set.distinct()
with findUnique()
.link(_ property:, conditions:)
method on your query.Order
that has a property ToOne<Order, Customer>
pointing to the customer that placed the order, you could select all orders belonging to a particular customer from today's orders usingjoin
.Property<Entity, Value, ReferencedType>
itself encode so much interesting information already to make the query interface very intuitive, for example: Property<E, String, R>
exposes methods that make sense for strings, like contains
Property<E, Int, R>
exposes methods that make sense for numbers, including comparisonsProperty<E, Date, R>
exposes methods for dates, like isBetween(_:and:)
QueryCondition
, the type used for queries, and a lot of them have intuitive operator variants. Please refer to the API docs for a full list of operators and methods.