Skip to content

Module: Database Manager

DBManagement

Create DBManagement module

Examples:

>>> from promg.modules.db_management import DBManagement
>>> db_manager = DBManagement()

clear_db(replace=True)

Replace or clear the entire database by a new one.

Note

Note about difference between replacing and clearing.

  • Replace: results in an Empty database that is completely replaced with a new database.

    • Replacing a database is faster than clearing a database.
    • Only possible when
      • you have an Neo4j enterprise license
      • you are running a local instance on the free Neo4j desktop version
  • Clear: Results in an empty database, however constraints are still in place.

    • Clearing a database takes longer
    • Independent of license

Parameters:

Name Type Description Default
replace bool

boolean to indicate whether the database may be replaced

True

Examples:

>>> db_manager.clear(replace=True)
Results in an Empty database that is completely replaced with a new database
    (i.e. constraints are also removed)
>>> db_manager.clear(replace=False)
Results in an empty database, however constraints are still in place.
Clearing an entire database takes longer.

set_constraints()

Set constraints in Neo4j instance.

  • sysId property is used as index for (:Entity) nodes

Examples:

>>> db_managers.set_constraints()
sysId is used as index for (:Entity) nodes

get_all_rel_types()

Get all relationship types that are present in Neo4j instance

Returns:

Type Description
List[str]

A list of strings with all relationship types present in the Neo4j instance

get_all_node_labels()

Get all node labels that are present in Neo4j instance

Returns:

Type Description
Set[str]

A list of strings with all node labels present in the Neo4j instance

get_statistics()

Get the count of nodes per label and the count of relationships per type

Returns:

Type Description
List[Dict[str, any]]

A list containing dictionaries with the label/relationship and its count

print_statistics()

Print the statistics nicely using tabulate