Und da man das nicht selbst machen möchte, benutzt man einen Kontext-Manager.
Code: Alles auswählen
@route("/save_input_data", methods=["POST"])
def save_input_data(self):
input_data = structure(request.get_json(), Data)
session = self.database.session
with session.begin():
order = Order(
glykohl_percent=input_data.order.glykohl_percent,
normvolume_flow=input_data.order.normvolume_flow,
suction_pressure=input_data.order.suction_pressure,
temperature_suction_filter=input_data.order.temperature_suction_filter,
)
session.add(order)
session.flush()
for cooler in input_data.coolers:
order_cooler_link = OrderCoolerLink(
cooler_id=cooler.id,
order_id=order.id,
cooling_countercurrent=cooler.cooling_countercurrent,
gas_humidity_after_cooler=cooler.gas_humidity_after_cooler,
gas_humidity_before_cooler=cooler.gas_humidity_before_cooler,
gas_pressure=cooler.gas_pressure,
gas_temperature_in=cooler.gas_temperature_in,
gas_temperature_out=cooler.gas_temperature_out,
temperature_cooling_fluid_in=cooler.temperature_cooling_fluid_in,
temperature_cooling_fluid_out=cooler.temperature_cooling_fluid_out,
number_of_cooler=cooler.number_of_cooler,
)
session.add(order_cooler_link)
for gas in input_data.gases:
order_gas_link = OrderGasLink(
order_id=order.id,
gas_id=gas.id,
percentage=gas.percent
)
session.add(order_gas_link)