<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def export_to_pypsa(self, session, method='onthefly'):
 """Exports MVGridDing0 grid to PyPSA database tables Peculiarities of MV grids are implemented here. Derive general export method from this and adapt to needs of LVGridDing0 Parameters session: :sqlalchemy:`SQLAlchemy session object<orm/session_basics.html>` Description method: str Specify export method:: 'db': grid data will be exported to database 'onthefly': grid data will be passed to PyPSA directly (default) Notes ----- It has to be proven that this method works for LV grids as well! Ding0 treats two stationary case of powerflow: 1) Full load: We assume no generation and loads to be set to peak load 2) Generation worst case: """


        # definitions for temp_resolution table
        temp_id = 1
        timesteps = 2
        start_time = datetime(1970, 1, 1, 00, 00, 0)
        resolution = 'H'

        nodes = self._graph.nodes()

        edges = [edge for edge in list(self.graph_edges())
                 if (edge['adj_nodes'][0] in nodes and not isinstance(
                edge['adj_nodes'][0], LVLoadAreaCentreDing0))
                 and (edge['adj_nodes'][1] in nodes and not isinstance(
                edge['adj_nodes'][1], LVLoadAreaCentreDing0))]

        if method == 'db':

            # Export node objects: Busses, Loads, Generators
            pypsa_io.export_nodes(self,
                                  session,
                                  nodes,
                                  temp_id,
                                  lv_transformer=False)

            # Export edges
            pypsa_io.export_edges(self, session, edges)

            # Create table about temporal coverage of PF analysis
            pypsa_io.create_temp_resolution_table(session,
                                                  timesteps=timesteps,
                                                  resolution=resolution,
                                                  start_time=start_time)
        elif method == 'onthefly':

            nodes_dict, components_data = pypsa_io.nodes_to_dict_of_dataframes(
                self,
                nodes,
                lv_transformer=False)
            edges_dict = pypsa_io.edges_to_dict_of_dataframes(self, edges)
            components = tools.merge_two_dicts(nodes_dict, edges_dict)

            return components, components_data
        else:
            raise ValueError('Sorry, this export method does not exist!')