<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_database(graph, manager: Optional[Manager] = None, store_parts: bool = True, use_tqdm: bool = False):
 """Store a graph in a database. :param BELGraph graph: A BEL graph :param store_parts: Should the graph be stored in the edge store? :return: If successful, returns the network object from the database. :rtype: Optional[Network] """

    if manager is None:
        manager = Manager()

    try:
        return manager.insert_graph(graph, store_parts=store_parts, use_tqdm=use_tqdm)
    except (IntegrityError, OperationalError):
        manager.session.rollback()
        log.exception('Error storing graph')
    except Exception as e:
        manager.session.rollback()
        raise e