Retrieving values
Since values are stored as Node objects, object retrieval will look something like this:PYNDatabase.Node.Node.val
val
is a variable which contains the value of the Node, and is linked to the original dictionary object.
To retrieve a dynamic object, you can use the get
method.
The get
method is also the only way to retrieve values which contain characters not in the alphabet (+the underscore character).
This way, you can avoid writing code like this:
eval(f'PYNDatabase.Node.{name_of_node}.Node.val')
Command Usage:
PYNDatabase.get(name)
PYNDatabase.Node.get(name)
Examples:
Static value retrieval
from pyndb import PYNDatabase
db = PYNDatabse('filename.pyndb')
db.set('hello', 'world')
print(db.hello.val) # <--
Dynamically retrieving a value
from pyndb import PYNDatabase
db = PYNDatabse('filename.pyndb')
db.set('123', 456) # Note that the value type doesn't matter
# This will work...
print(db.get('123').val) # <--
# But this will not.
print(db.123.val)
Storing a Node inside a variable is also a great option!
from pyndb import PYNDatabase
db = PYNDatabse('filename.pyndb')
db.set('hello', 'world')
hello = db.hello # <--
print(hello.val)