wiki:VariableDatabase

Variable Database

Define structural code in an interface:

interfaces/home/Itham/conf::
    storage($db):
        items@0.0.1($table):
            - name: string
            - value: string
            - creation: datetime

Load the interface from an activity:

home/Itham/items::
    items$v001 = string(..conf).structure.storage['items@0.0.1']

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

        i.save()

    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')]))

Synthetic Agent System

- assets/Itham/server/kernel/api/synthetic$agentSystem
- assets/Itham/components/vardb/code/agentSystem$localOpen
- assets/Itham/components/vardb/code/agentSystem$endpointOpen

Compiler Classes

def install$MS3NF(synth$db):
    run$python(code, mapping(db = synth$db)) <- code:
        from ph.interpreter.mental.library.model import Filesystem

        db._core._compilerClass = Filesystem.Node.Module.MappingSchema3rdNFCompiler
        db._core._compilerClass._setOutputCompiler \
            (Filesystem.Node.Module.TranspileCompiler)


def test():
    db = synth$open(structure(..db$schema).ms3nf)
    install$MS3NF(db)

    '.../kernel/module_ms3nf'('xyz') \
        .setText('.../kernel/edit'('abc/def'), code) <- code:

        return 'An algorithm compiled into ms3nf: %s %s' % [args$(), keywords$()]

    return act(db, [initialize, 'abc/def/xyz'] + args$(), keywords$())


interfaces/db$schema::
    ms3nf(db):
        ast$list$key(table):
            []

        ast$list$value(table):
            []
Last modified 6 months ago Last modified on 05/30/23 13:46:51
Note: See TracWiki for help on using the wiki.