The Realm C++ SDK currently supports these property types.
Los opcionales utilizan la plantilla de clase std::opcional.
Property Cheat Sheet
You can use the following types to define your object model properties.
Para aprender cómo se asignan tipos de datos específicos a los BSON types en un esquema de App Services, consulta Mapeo del modelo de datos en la documentación de Atlas App Services.
Tipo | Requerido | Opcional | ||
|---|---|---|---|---|
bool | | | ||
Int64 | | | ||
Double | | | ||
String | | | ||
enum | | | ||
Datos binarios | | | ||
fecha | | | ||
Decimal128 | | | ||
UUID | | | ||
Object ID | | | ||
Mixed Data Type | | N/A | ||
Map | | N/A | ||
Lista | | N/A | ||
Configura | | N/A | ||
User-defined Object | N/A | | ||
User-defined Embedded Object | N/A | |
Supported Type Implementation Details
Some of the supported types above are aliases for:
mixedUn objeto similar a una unión que puede representar un valor de cualquiera de los tipos admitidos. Se implementa mediante la plantilla de clase std::variant. Esta implementación significa que unamixedpropiedad contiene un valor de uno de sus tipos alternativos o, en caso de error, ningún valor.Para las fechas, utiliza la librería chrono para almacenar un
time_pointrelativo a lasystem_clock:<std::chrono::time_point<std::chrono::system_clock>>
Mapa/Libro de registros (dictionary)
The Map is an associative array that contains key-value pairs with unique keys.
You can declare a Map as a property of an object:
namespace realm { struct Dog { std::string name; std::map<std::string, std::string> favoriteParkByCity; }; REALM_SCHEMA(Dog, name, favoriteParkByCity) } // namespace realm
String is the only supported type for a map key, but map values can be:
Required versions of any of the SDK's supported data types
Optional user-defined object links
Optional embedded objects
Realm disallows the use of . or $ characters in map keys. You can use percent encoding and decoding to store a map key that contains one of these disallowed characters.
// Percent encode . or $ characters to use them in map keys auto mapKey = "Monday.Morning"; auto encodedMapKey = "Monday%2EMorning";
Collection Types
Realm has several types to represent groups of objects, which we call collections. A collection is an object that contains zero or more instances of one Realm type. Realm collections are homogenous: all objects in a collection are of the same type.
You can filter and sort any collection using Realm's query engine. Collections are live, so they always reflect the current state of the realm instance on the current thread. You can also listen for changes in the collection by subscribing to collection notifications.
Resultados
La colección de resultados del SDK de C++ es un tipo Results que representa los objetos recuperados de las consultas. Una colección representa los resultados evaluados de forma diferida de una operación de consulta. Los resultados son inmutables: no se pueden añadir ni eliminar elementos de la colección. Los resultados tienen una consulta asociada que determina su contenido.
For more information, refer to the Read documentation.
Configura
La colección de conjuntos del C++ SDK representa una relación de uno a muchos que contiene valores distintos. Un set SDK de C++ admite los siguientes tipos (y sus versiones opcionales):
Datos binarios
bool
Double
fecha
Int64
Mezclado
ObjectId
Objeto
String
UUID
Like the C++ std::set, the C++ SDK set is a generic type that is parameterized on the type it stores.
You can only call set mutation methods during a write transaction. You can register a change listener on a mutable set.
Collections as Properties
El SDK de C++ también ofrece varios tipos de colecciones que puedes usar como propiedades en tu modelo de datos:
List, a type representing to-many relationships in models.
Set, a type representing to-many relationships in models where values are unique.
linking_objects, un tipo que representa relaciones inversas en los modelos.
Map, a type representing an associative array of key-value pairs with unique keys.
Las colecciones están en tiempo real
Like live objects, Realm collections are usually live:
Live results collections always reflect the current results of the associated query.
Live lists always reflect the current state of the relationship on the realm instance.
The one case when a collection is not live is when the collection is unmanaged. For example, a List property of a Realm object that has not been added to a realm yet or that has been moved from a realm is not live.
Combinado con notificaciones de colección, las colecciones en tiempo real permiten un código limpio y reactivo. Por ejemplo, supón que tu vista muestra los resultados de una query. Puedes mantener una referencia a la colección de resultados en tu código vista, y luego leer la colección de resultados según sea necesario sin tener que actualizarla o validar que esté actualizada.
Importante
Results indexes may change
Dado que los resultados se actualizan automáticamente, no se debe almacenar el índice posicional de un objeto en la colección ni la cuenta de objetos en una colección. El índice almacenado o el valor de la cuenta podría estar desactualizado para cuando lo utilices.