Realm.js: saving an unstructured object as a property

We have a content delivery application where we destroy objects on our JSON that are dynamic in structure. React Native uses JSON and creates a user interface from these objects.

This is the scheme I'm working with now:

const CardSchema = {
    name: 'Card',
    properties: {
        id: 'string',
        cardSubType: 'string',
        cardType: 'string',
        state: 'string',
        contentType: 'string',
        context: {},
    },
};

The field contextis a dynamic part. This is basically an object that can have any number of fields. At compile time, we don’t know which fields are there.

We want to use realm.js to save our data, because it is good and fast, and we can use 99% of our objects at compile time.

This is only one field (and several others), on which we want to store any object.

Realm for React Native? ?

+4
1

/ . - , JSON. , , , JSON. -

const UNDEFINEDTYPE = 0;
const INTTYPE = 1;
const STRINGTYPE = 2;

const JSONValueSchema = {
    name: 'JSONValue',
    properties: {
        type: 'int',
        stringValue: { type: 'string', optional: true },
        intValue:    { type: 'int', optional: true },
        jsonValue:   { type: 'JSON', optional: true },        
    }
};

const JSONEntrySchema = {
    name: 'JSONEntry',
    properties: {
        key: 'string',
        value: 'string'
    }
};

const JSONSchema = {
    name: 'JSON',
    properties: {
        entries: { type: 'list', objectType: 'JSONEntry' }
    }
}

, keyPath, BLOB- JSON CONTAINS. , , .

+3

Source: https://habr.com/ru/post/1648657/


All Articles