Variable Database

Define structural code in an interface:

            - name: string
            - value: string
            - creation: datetime

Load the interface from an activity:

    items$v001 = string(..conf)['items@0.0.1']

    def newItem(name, value):
        for i in items$v001.get('name', name):
            i.value = 'text/json/dumps'(value)
            # The order of arguments in this constructor must match conf.
            i = items$v001(name, 'text/json/dumps'(value), now())

    def getItemValue(name):
        for i in items$v001.get('name', name):
            return 'text/json/loads'(i.value)

    def getItem$(name):
        return .getItemValue(name)
    def setItem$(name, value):
        .newItem(name, value)

    return $(..items)

In order to open the database with the .structure property it must be configured in the filesystem. The name of the database (storage) must be included in the configuration in order to differentiate databases in a single interface:

agent vardb add variables/key-value/items-1.sqlite 10000000 home Itham conf storage

Initialize the activity module and load key-value data:

initialize('home/Itham/items')['player:itham:world:0000'] = \
    mapping(name = 'My world', rooms = \
            mapping([01, mapping(name = 'My room')]))
Last modified 3 weeks ago Last modified on 09/09/22 14:35:43
Note: See TracWiki for help on using the wiki.