The GlobalDB example demonstrates how you can create and delete data into the GlobalDB. This example consists of one python script /demoGlobalDB.py and manifest file /manifest.json.
from DAP.Core import logIt
from CellFrame.Chain import GlobalDB
def init():
logIt.notice("Running plugin client")
# Creates an entry in globalDB
GlobalDB.set("test", "local.mygroup", "ENX".encode('utf-8'))
# Reads the content from the newly created entry.
term = GlobalDB.get("test", "local.mygroup")
# Deletes the created entry.
GlobalDB.delete("test", "local.mygroup")
logIt.notice("Data reading form group local.mygroup key test: "+str(term))
return 0
def deinit():
logIt.notice("Plugin client deinit")
{
"name": "notifyDB",
"version": "1.0",
"author": "DEMLABS (C) 2021",
"dependencies": [],
"description": "This plugin demonstrates a work with notification."
}
This /demoGlobalDB.py script contains a function: init
.
The execution of the plugin starts with the init
.
1. The plugin is initialized by the init
function:
def init():
2. Logging the message:
logIt.notice("Running plugin client")
3. Adding a data into the GlobalDB using a set
method of the GlobalDB
class:
GlobalDB.set("test", "local.mygroup", "ENX".encode('utf-8'))
The "test"
is a key, "local.mygroup"
is a local group and "ENX"
is a data
4. Getting a data from the GlobalDB using a get
method of the GlobalDB
class:
term = GlobalDB.get("test", "local.mygroup")
5. Deleting a data from the GlobalDB using a delete
method of the GlobalDB
class:
GlobalDB.delete("test", "local.mygroup")
6. Logging the message:
logIt.notice("Data reading form group local.mygroup key test: "+str(term)
7. Returning 0
. This means that the plugin has been successfully initialized:
return 0