# Path: datapackage_pipelines/wrapper/wrapper.py
# def ingest(debug=False):
#     params, datapackage, resource_iterator = _ingest(debug=debug)
#     return ProcessorContext(params, datapackage, resource_iterator)
# 
# Path: datapackage_pipelines/utilities/flow_utils.py
# def spew_flow(flow, ctx: ProcessorContext):
#     flow = Flow(
#         update_package(**ctx.datapackage),
#         load((ctx.datapackage, ctx.resource_iterator)),
#         flow,
#     )
#     datastream = flow.datastream()
#     ctx.datapackage = datastream.dp.descriptor
#     ctx.resource_iterator = datastream.res_iter
#     ctx.stats = MergeableStats(datastream.stats, ctx.stats)


from dataflows import Flow, dump_to_sql
from datapackage_pipelines.wrapper import ingest
from datapackage_pipelines.utilities.flow_utils import spew_flow


def flow(parameters):
    return Flow(
        dump_to_sql(
            parameters['tables'],
            engine=parameters.get('engine', 'env://DPP_DB_ENGINE'),
            updated_column=parameters.get("updated_column"),
            updated_id_column=parameters.get("updated_id_column")
        )
    )


if __name__ == '__main__':
    with ingest() as ctx:

# Path: datapackage_pipelines/wrapper/wrapper.py
# def ingest(debug=False):
#     params, datapackage, resource_iterator = _ingest(debug=debug)
#     return ProcessorContext(params, datapackage, resource_iterator)
# 
# Path: datapackage_pipelines/utilities/flow_utils.py
# def spew_flow(flow, ctx: ProcessorContext):
#     flow = Flow(
#         update_package(**ctx.datapackage),
#         load((ctx.datapackage, ctx.resource_iterator)),
#         flow,
#     )
#     datastream = flow.datastream()
#     ctx.datapackage = datastream.dp.descriptor
#     ctx.resource_iterator = datastream.res_iter
#     ctx.stats = MergeableStats(datastream.stats, ctx.stats)


# Path: datapackage_pipelines/lib/dump_to_sql.py
from dataflows import Flow, dump_to_sql
from datapackage_pipelines.wrapper import ingest
from datapackage_pipelines.utilities.flow_utils import spew_flow



def flow(parameters):
    return Flow(
        dump_to_sql(
            parameters['tables'],
            engine=parameters.get('engine', 'env://DPP_DB_ENGINE'),
            updated_column=parameters.get("updated_column"),
            updated_id_column=parameters.get("updated_id_column")
        )
    )


if __name__ == '__main__':
    with ingest() as ctx:

        spew_flow(flow(ctx.parameters), ctx)