Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-1253

[C-API] Expose a way for SDKs to set class/property keys when creating the schema

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      Describe your problem or use case

      Currently we have an API to get collections by TableKey and properties by ColKey (exposed as realm_class_key_t and realm_property_key_t in the C API). The issue with this API is that those values are only available at runtime, so SDKs are forced to construct the schema, then query Core to map the TableKey/ColKey to our local data models. This is typically done by keeping dictionaries mapping Type->TableKey and string->ColKey, then in the property getters, we'll do something like:

      Unable to find source-code formatter for language: dart. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class MyObject {
        static Map<String, int> properties = {};
      
        int foo {
          get {
            var colKey = properties['foo']
            return realmCore.getValue(this, colKey) as int;
          }
        }
      }
      

      A lot of that can be simplified (and in some cases optimized), if we were allowed to provide an "id" when constructing the schema. Then OS/Core would be responsible for mapping the id to the ObjectSchema, turning the code into something like:

      Unable to find source-code formatter for language: dart. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class MyObject {
        int foo {
          get {
            // Here 1 is the generated id for this property and is a compile-time constant
            return realmCore.getValue(this, 1) as int;
          }
        }
      }
      

      I believe something like this may be achievable already for users of the C++ API as the persisted_properties and computed_properties vectors are populated based on the schema supplied by the SDK, so their indices should be in sync with whatever the SDK provided, but it only covers properties, not classes, and even then it's not available to the C API.

            Assignee:
            Unassigned Unassigned
            Reporter:
            nikola.irinchev@mongodb.com Nikola Irinchev
            AD Core
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: