-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set support - API #3378
Comments
➤ Franck Franck commented: Comments:
|
How can i filter by set. Suppose i have a set ["q34q234","asdfawer"] i need to filter by "q34q234". How can i ?. Please provide an example with all conditions like AND, OR, NOT .. etc., One more question. if add same key to set, will it be replaced or shows error key already exists? |
@somasekharkakarla For examples, our tests might be useful: https://github.com/realm/realm-js/blob/main/integration-tests/tests/src/tests/sets.ts#L292 |
Introduction
JavaScript has - since ES6 - supported Set objects.
In Realm Core/Sync, a set is a collection of unique values which are immutable. It is assumed that Realm Query Language will support sets, and it is not required additional work for Realm JavaScript to support it.
To be consistent with the current API, a new class
Realm.Set
is implemented. The class inherits fromRealm.Collection
.Schema
The canonical form of a schema with a set property (
scores
). We follow the same pattern as link lists:For a short form, we can add a suffix after the type. For link lists, we are using
[]
. In the following we will assume that we are using angle brackets (<>
) for sets.The schema can be written as:
For a composite object (not primitive type), the schema will look like this:
Creating objects with sets
When creating Realm objects, you can specify elements for a set property using an array.
For composite objects, creating an object is:
Properties
size
Unlike JavaScript arrays, JavaScript sets have a property called
size
to get the number of elements in the set.Methods
A JavaScript set object has a number of methods. We seek to be consistent with the ES6 specification.
add
The method appends a new element to the set.
Moreover, it is possible to to add objects:
An exception will be thrown if the element does not validate according to the schema. The method will return a reference to the set object to make it simpler to chain calls.
clear
The method deletes references to all elements.
delete
The method deletes the reference to one element.
For a composite object:
entries
forEach
has
Listeners
The text was updated successfully, but these errors were encountered: