yawning_titan.networks.network_db.NetworkDB#
- class yawning_titan.networks.network_db.NetworkDB[source]#
Bases:
object
The
NetworkDB
class extendsYawningTitanDB
.The below code blocks demonstrate how to use the
NetworkDB
class.Instantiate the Network DB:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkSchema >>> db = NetworkDB()
Search for all network that have set_random_entry_nodes == True.
>>> db.search(NetworkSchema.SET_RANDOM_ENTRY_NODES == True)
Methods
Get all
Network
from the network DB.Count how many docs are in the db.
Get a network config document from its uuid.
Insert a
Network
into the DB as.json
.Rebuild the db.
Remove a
Network
.Remove
Network
.Reset the default network in the db.
Searches the
Network
with aNetworkSchema
query.Show details of all entries in the db.
Update a
Network
.Upsert a
Network
.- insert(network, name=None, description=None, author=None)[source]#
Insert a
Network
into the DB as.json
.
- show(verbose=False)[source]#
Show details of all entries in the db.
- Parameters:
verbose – If True, all doc metadata details are shown, otherwise just the name is shown.
- get(uuid)[source]#
Get a network config document from its uuid.
- Parameters:
uuid – A target document uuid.
- Returns:
The network config document as an instance of
Network
if the uuid exists, otherwiseNone
.
- search(query)[source]#
Searches the
Network
with aNetworkSchema
query.- Parameters:
query – A
YawningTitanQuery
.- Returns:
- count(cond=None)[source]#
Count how many docs are in the db. Extends
tinydb.table.Table.count
.A
YawningTitanQuery
can be used to filter the count.- Parameters:
cond – An optional
YawningTitanQuery
. Has a default value ofNone
.- Returns:
The number of docs counted.
- remove_by_cond(cond)[source]#
Remove
Network
. from the db that match the query.- Parameters:
cond – A
YawningTitanQuery
.- Returns:
The list of uuids of the removed
Network
.
- reset_default_networks_in_db(force=False)[source]#
Reset the default network in the db.
Achieves this by loading the default yawning_titan/networks/_package_data/network.json db file into TinyDB, then iterating over all docs and forcing an update of each one in the main networks db from its uuid if they do not match.
- Parameters:
force – Forces a reset without checking for equality when True. Has a default value of False.
- rebuild_db()[source]#
Rebuild the db.
- Actions taken:
clear the query cache
truncate the db
Warning
This function completely rebuilds the database. Any custom networks saved in the db will be lost. The default networks can be reset using the
reset_default_networks_in_db()
function.