-
Notifications
You must be signed in to change notification settings - Fork 88
(DOCSP-39513): Consolidate Create page #3270
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
Changes from all commits
b6de91a
1e5a5b2
5439868
9a10b93
54d233d
439d26b
b55c6d3
771dd89
a51f41e
71d8730
4d3a074
4c59437
cdc6d0b
1d356b2
0560132
e1c959c
e83a7fa
00345a2
437558d
3091195
3b47dff
bc519af
c8bd56b
d1a72ee
0aa049e
3b6a6dc
61a47a9
6df1040
9d2b19c
f39ab91
3193d0e
c8657b2
ba686c7
4a4640f
d91db04
6239d0c
fb89087
19b0f29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This API is not currently supported in C++. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The C++ SDK does not currently provide a dedicated counter property type. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
When you create an object that has a | ||
:cpp-sdk:`map property <structrealm_1_1managed_3_01std_1_1map_3_01std_1_1string_00_01T_01_4_00_01void_01_4.html>`, | ||
you can set the values for keys in a few ways: | ||
|
||
- Set keys and values on the object and then add the object to the database | ||
- Set the object's keys and values directly inside a write transaction | ||
|
||
.. include:: /includes/map-key-string-limitations.rst | ||
|
||
.. literalinclude:: /examples/generated/cpp/crud.snippet.percent-encode-disallowed-characters.cpp | ||
:language: cpp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The C++ SDK does not currently support geospatial data. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
To create an object with a inverse relationship to another object, | ||
assign the raw pointer of the related object to the relationship | ||
property of the main object. Move the object into the realm using the | ||
:cpp-sdk:`Realm.add() function <structrealm_1_1db.html>` | ||
inside of a write transaction. | ||
|
||
In this example, we create two ``Person`` objects that each have a to-one | ||
relationship to the same ``Dog`` object. The ``Dog`` has an inverse | ||
relationship to each ``Person`` object. The inverse relationship backlink | ||
is automatically updated when a linked ``Person`` object updates its | ||
``Dog`` relationship. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
To create an object with a list property (to-many relationship) to one or | ||
more objects: | ||
|
||
- Initialize the main object and the related objects | ||
- Use the :cpp-sdk:`push_back | ||
<structrealm_1_1managed_3_01std_1_1vector_3_01T_01_5_01_4_01_4.html>` | ||
member function available to the SDK object lists | ||
to append the raw pointers of the related objects to the main object's | ||
list property | ||
- Move the object into the realm using the | ||
:cpp-sdk:`Realm.add() function <structrealm_1_1db.html>` | ||
inside of a write transaction. | ||
|
||
In this example, we append the raw pointers of the related objects - | ||
``Employee *`` - to the relationship property of the main object | ||
- ``Company.employees``. This creates a one-way connection from the | ||
``Company`` object to the ``Employee`` objects. | ||
|
||
Then, we add the ``Company`` to the database. This copies the | ||
``Company`` and ``Employee`` objects to the database. | ||
|
||
The related ``Employee`` objects have their own lifecycle independent | ||
of the main ``Company`` object. If you delete the main object, the | ||
related objects remain. | ||
|
||
You can optionally create an inverse relationship to refer to the main object | ||
from the related object. For more information, refer to: | ||
:ref:`sdks-create-object-with-inverse-relationship`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
When you create an object with a ``realm::mixed`` value, you must specify the | ||
type of the value you store in the property. The SDK provides a ``type()`` | ||
function you can call to determine what type of data the property has stored. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Create a unique Object ID with ``realm::object_id::generate()``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
To create an object, you must instantiate it using the ``realm`` namespace. | ||
Move the object into the realm using the | ||
Move the object into the database using the | ||
:cpp-sdk:`Realm.add() function <structrealm_1_1db.html>` | ||
inside of a write transaction. | ||
|
||
When you move an object into a realm, this consumes the object as an | ||
When you move an object into a database, this consumes the object as an | ||
rvalue. You must use the managed object for any data access or observation. | ||
In this example, copying the ``dog`` object into the realm consumes | ||
In this example, copying the ``dog`` object into the database consumes | ||
it as an rvalue. You can return the managed object to continue to work | ||
with it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
You can create objects that contain | ||
:cpp-sdk:`set <structrealm_1_1managed_3_01std_1_1set_3_01T_01_5_01_4_01_4.html>` | ||
properties as you would any SDK object, but you can only mutate a set | ||
property within a write transaction. This means you can only set the value(s) | ||
of a set property within a write transaction. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Use the `chrono library | ||
<https://en.cppreference.com/w/cpp/chrono>`__ | ||
to store a ``time_point`` relative to the ``system_clock``: | ||
``<std::chrono::time_point<std::chrono::system_clock>>`` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
To create an object with a to-many relationship to one or more objects: | ||
|
||
- Initialize the main object and the related objects | ||
- Use the :cpp-sdk:`push_back | ||
<structrealm_1_1managed_3_01std_1_1vector_3_01T_01_5_01_4_01_4.html>` | ||
member function available to the Realm object lists | ||
to append the raw pointers of the related objects to the main object's | ||
list property | ||
- Move the object into the realm using the | ||
:cpp-sdk:`Realm.add() function <structrealm_1_1db.html>` | ||
inside of a write transaction. | ||
|
||
In this example, we append the raw pointers of the related objects - | ||
``Employee *`` - to the relationship property of the main object | ||
- ``Company.employees``. This creates a one-way connection from the | ||
``Company`` object to the ``Employee`` objects. | ||
|
||
Then, we add the ``Company`` to the realm. This copies the | ||
``Company`` and ``Employee`` objects to the realm. | ||
|
||
The related ``Employee`` objects have their own lifecycle independent | ||
of the main ``Company`` object. If you delete the main object, the | ||
related objects remain. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
To create an object with a to-one relationship to another object, | ||
assign the raw pointer of the related object to the relationship | ||
property of the main object. Move the object into the database using | ||
the :cpp-sdk:`Realm.add() function <structrealm_1_1db.html>` | ||
inside of a write transaction. | ||
|
||
In this example, we assign the raw pointer of the related object - | ||
``FavoriteToy *`` - to the relationship property of the main object | ||
- ``Dog.favoriteToy``. Then, when we add the ``dog`` object to the | ||
database, this copies both the ``dog`` and ``favoriteToy`` to the database. | ||
|
||
The related ``favoriteToy`` object has its own lifecycle independent | ||
of the main ``dog`` object. If you delete the main object, the related | ||
object remains. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Create an unmanaged version of a managed object by calling the ``detach()`` | ||
function. This returns a value of the managed type. For example, calling | ||
the ``detach()`` function on a managed string property of a managed object | ||
returns a ``std::string`` copy of that property. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
You can create a UUID with ``realm::uuid()``. Or you can initialize a UUID | ||
with a specific value, similar to ``realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002")``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Traditionally, you would implement a counter by reading a value, incrementing | ||
it, and then setting it (``myObject.Counter += 1``). This does not work well in | ||
an asynchronous situation like when two clients are offline. Consider | ||
the following scenario: | ||
|
||
- The SDK object has a ``counter`` property of type ``int``. It is currently | ||
set to a value of ``10``. | ||
|
||
- Clients 1 and 2 both read the ``counter`` property (``10``) and each increments | ||
the value by ``1``. | ||
|
||
- When each client regains connectivity and merges their changes, they expect a | ||
value of 11, and there is no conflict. However, the counter value should be | ||
``12``! | ||
|
||
When using a ``RealmInteger``, however, you can call the ``Increment()`` and | ||
``Decrement()`` methods, and to reset the counter, you set it to ``0``, just as | ||
you would an ``int``. | ||
|
||
.. important:: | ||
|
||
When you reset a ``RealmInteger``, you may run into the offline merge issue | ||
described above. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
You create a list collection property by defining a getter-only property of type | ||
`IList<T> <https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ilist-1?view=net-5.0>`_, | ||
where ``T`` can be any data type (except other collections). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.. note:: | ||
|
||
You cannot create a nullable ``RealmValue``. However, if you want a | ||
``RealmValue`` property to contain a null value, you can | ||
use the special ``RealmValue.Null`` property. | ||
|
||
The following code demonstrates creating a ``RealmValue`` property in a class | ||
that inherits from ``IRealmObject`` and then setting and getting the value of | ||
that property: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
You can create multiple items in the database using the | ||
:dotnet-sdk:`Add<T>(IEnumerable<T>, bool) <Realms.Realm.html#Realms_Realm_Add__1_System_Collections_Generic_IEnumerable___0__System_Boolean_>` | ||
method. It takes a collection of standalone ``IRealmObject`` instances to | ||
add to the database. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Create a unique Object ID with ``ObjectId.GenerateNewId()``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Open a write transaction with the | ||
or :dotnet-sdk:`Realm.WriteAsync() <reference/Realms.Realm.html#Realms_Realm_WriteAsync_System_Action_System_Threading_CancellationToken_>` | ||
method to avoid blocking the UI thread. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Upserting a document is the same as creating a new one, except you set the | ||
optional ``update`` parameter to ``true``. In this example, we create a new | ||
``Item`` object with a unique ``Id``. We then insert an item with the | ||
same id but a different ``Name`` value. Because we have set the ``update`` | ||
parameter to ``true``, the existing record is updated with the new name. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Use ``DateTimeOffset`` to store timestamp data. The SDK converts | ||
``DateTimeOffset`` values to UTC before storing in the database, and does not | ||
store the timezone information. | ||
|
||
See :github:`Issue #1835 </realm/realm-dotnet/issues/1835>` for more | ||
information. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Once you have an open Realm, you can create an asymmetric object inside | ||
Once you have an open database, you can create an asymmetric object inside | ||
a write transaction. Pass your object data to ``realm.ingest``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The Flutter SDK does not currently provide a dedicated counter property type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're super inconsistent in the (Personally, I like specifying the SDK language where possible, since it provides clarity) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
You can create a relationship between one object and any number of objects | ||
using a property of type ``List<T>`` in your application, where T is an SDK | ||
model class. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
To add a ``RealmValue`` to an object, call ``RealmValue.from()`` on the data | ||
or ``RealmValue.nullValue()`` to set a null value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To add multiple objects to a database, pass a list of multiple objects | ||
to :flutter-sdk:`Realm.addAll() <realm/Realm/addAll.html>` inside a write | ||
transaction block. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Call ``ObjectId()`` to set any unique identifier properties of | ||
your object. Alternatively, pass a string | ||
to ``ObjectId()`` to set the unique identifier property to a specific value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
You can add, modify, or delete objects asynchronously using | ||
:flutter-sdk:`Realm.writeAsync() <realm/Realm/writeAsync.html>`. | ||
|
||
When you use ``Realm.writeAsync()`` to perform write operations, waiting | ||
to obtain the write lock and committing a transaction occur in the background. | ||
Only the write itself occurs on the main process. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
To upsert an object, call :flutter-sdk:`Realm.add() <realm/Realm/add.html>` | ||
with the optional ``update`` flag set to ``true`` inside a transaction block. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Use ``DateTime`` to store timestamp data. | ||
|
||
However, it is important to note that the SDK stores ``DateTime`` in UTC. | ||
When you use ``DateTime``, you must create it in UTC or convert it | ||
with ``.toUtc()`` before you store it. If your application requires it, | ||
you can convert it back to local or the desired time zone when reading | ||
from the database. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To set any unique identifier properties of | ||
your object to a random value, call one of the ``Uuid`` methods to create a UUID, | ||
such as ``Uuid.v4()``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
To copy a managed object to another database instance, call the | ||
:js-sdk:`Realm.create() <classes/Realm-1.html#create>` method in a write | ||
transaction with the object to copy. You can optionally specify the | ||
:js-sdk:`UpdateMode <enums/Realm.UpdateMode.html>` to determine how to handle | ||
copying objects where the target database instance already contains an object | ||
with a matching primary key. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,2 @@ | ||||||
The selected language does not currently have an example of how to copy an | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
this includes is potentially confusing. We don't preface other examples with this -- also, we're saying there's there's no example, but we also don't have any info on how to do it (api link, etc.)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the SDKs where I've used this include, I wasn't able to find a special API for this. Not all of the SDKs expose a method to do this. There may be a way to do this using the "normal" APIs. For the SDKs where I've used this include, I've added providing an example of this to the relevant ticket in the SDK's consolidation gaps epic. It would be nice to have that info on the page from the beginning, but for things where I don't know the technical implementation details off the top of my head, I'm trying not to hold up the consolidation epic. There are so many gaps. Maybe we can pull in the engineering teams to help with the gaps? 🤔 |
||||||
object to another database instance. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
However, in this example, because the ``MyGeoPoint`` class does not | ||
extend ``Realm.Object``, we must specify ``MyGeoPoint.schema`` when opening | ||
the database: |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||
This SDK does not provide specialized methods to initialize objects with | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can use "selected SDK language" for things like this include. For a concrete example - let's say "Swift" is the language that someone has selected. We're saying right after this to "use standard language features to create objects with initial values." So if the reader replaces "selected SDK language" with "Swift" (the language that they have selected), this would read:
That - doesn't make sense. It isn't that the language doesn't provide the feature. It's that the SDK doesn't expose an API to do this, so we want you to use language features to do it, instead. I know the user has selected a programming language and we're referring to SDK, but I think we have to be specific about SDK here. |
||||||
a value. Instead, use standard language features to create objects with | ||||||
initial values, or set the values after creating an object. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||
The SDK does not have a dedicated API to create multiple objects. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion to improve readability when this snippet's used:
or maybe a use case for the substitution directive?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the same reason as above, I don't think we can use "selected SDK language" here. We're not talking about the programming language, we're specifically saying that the SDK does not have an API for this. I also don't think we need to link to the "create one object" section - it's there in the OTP and it's also right above this section, so it seems unnecessary to link to it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This language is currently missing an example of how to create objects from | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so all SDKs support this, but we just don't have it documented in most of them?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to find a dedicated API for this for most SDKs. But it's a very common use case, so I think we should create an idiomatic example for SDKs where we don't have a dedicated API. For SDKs that don't have a dedicated API, it may be - for Kotlin, for example, maybe defining a custom serializer, or for some of the other languages, maybe for Swift, it's creating a custom decoder and then doing a map over the values, etc. I've added this as a line item to the consolidation gaps tickets. |
||
JSON. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Use the ``date`` property type to store timestamp data. This maps to the | ||
JavaScript :mdn:`Date <Web/JavaScript/Reference/Global_Objects/Date>` type. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The API to create an unmanaged copy of an object is either not needed or | ||
not currently supported in this SDK. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To set any unique identifier properties of | ||
your object to a random value, call ``new UUID()``. Alternatively, pass a string | ||
to ``new UUID()`` to set the unique identifier property to a specific value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Use :java-sdk:`realm.copyToRealm() <io/realm/Realm.html#copyToRealm(E,io.realm.ImportFlag...)>` | ||
in a write transaction to copy a managed object to another database instance. | ||
|
||
Alternately, to copy an object that does not exist, or update an object that | ||
does exist, use :java-sdk:`realm.copyToRealmOrUpdate() | ||
<io/realm/Realm.html#copyToRealmOrUpdate(E,io.realm.ImportFlag...)>`. This | ||
copies an object where the target database instance does not contain an | ||
object with the same primary key. If the target database instance already | ||
contains an object with a matching primary key, it updates the object. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Typically, incrementing or decrementing a | ||
``byte``, ``short``, ``int``, or ``long`` field of a Realm | ||
object looks something like this: | ||
|
||
1. Read the current value of the field. | ||
#. Update that value in memory to a new value based on the increment or | ||
decrement. | ||
#. Write a new value back to the field. | ||
|
||
When multiple distributed clients attempt this at the same time, | ||
updates reaching clients in different orders can | ||
result in different values on different clients. ``MutableRealmInteger`` | ||
improves on this by translating numeric updates into sync operations | ||
that can be executed in any order to converge to the same value. | ||
|
||
The :java-sdk:`counter.increment() <io/realm/MutableRealmInteger.html#increment-long->` | ||
and :java-sdk:`counter.decrement() <io/realm/MutableRealmInteger.html#decrement-long->` | ||
operators ensure that increments and decrements from multiple distributed | ||
clients are aggregated correctly. | ||
|
||
To change a :java-sdk:`MutableRealmInteger | ||
<io/realm/MutableRealmInteger.html>` value, call ``increment()`` or | ||
``decrement()`` within a write transaction. | ||
|
||
You can assign a ``MutableRealmInteger`` a new value with a call to | ||
:java-sdk:`counter.set() <io/realm/MutableRealmInteger.html#set-long->` | ||
within a write transaction. | ||
|
||
.. warning:: Counter Resets | ||
|
||
Use the ``set()`` operator with extreme care. ``set()`` ignores | ||
the effects of any prior calls to ``increment()`` or ``decrement()``. | ||
Although the value of a ``MutableRealmInteger`` always converges | ||
across devices, the specific value on which it converges depends on | ||
the actual order in which operations took place. | ||
Mixing ``set()`` with ``increment()`` and ``decrement()`` is | ||
not advised unless fuzzy counting is acceptable. | ||
|
||
.. literalinclude:: /examples/generated/java/local/WritesTest.snippet.counter-set.java | ||
:language: java | ||
|
||
Since ``MutableRealmInteger`` instances retain a reference to their | ||
parent object, neither object can be garbage collected while you still | ||
retain a reference to the ``MutableRealmInteger``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want a link to the API ref for
detach()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no API ref for
detach()
, alas.