1414from fundamend .sqlmodels .anwendungshandbuch import Paket , UbBedingung
1515
1616try :
17- from sqlalchemy .sql .functions import func
1817 from sqlmodel import Field , Session , SQLModel , UniqueConstraint , col , select
1918
2019except ImportError as import_error :
@@ -186,6 +185,7 @@ def create_and_fill_ahb_expression_table(session: Session, use_cpu_intensive_val
186185 if (key := (row [0 ], row [1 ], row [2 ].strip ())) not in seen
187186 and not seen .add (key ) # type:ignore[ func-returns-value]
188187 ]
188+ ahb_expression_rows : list [AhbExpression ] = []
189189 for row in unique_rows : # there are ~3600 unique rows for FV2410+FV2504 as of 2025-04-15
190190 expression = row [2 ].strip ()
191191 if use_cpu_intensive_validity_check :
@@ -195,30 +195,23 @@ def create_and_fill_ahb_expression_table(session: Session, use_cpu_intensive_val
195195 )
196196 else :
197197 _ , node_texts , error_message = _get_validity_node_texts_and_error_message_fast (expression , session , row [3 ])
198- ahb_expression_row = AhbExpression (
199- edifact_format_version = row [0 ],
200- format = row [1 ],
201- expression = expression ,
202- node_texts = node_texts ,
203- anwendungshandbuch_primary_key = row [3 ],
204- ahbicht_error_message = error_message ,
205- )
206- session .add (ahb_expression_row )
207- _logger .debug (
208- "Added row (%s, %s, %s) to the ahb_expressions_table" ,
209- ahb_expression_row .edifact_format_version ,
210- ahb_expression_row .format ,
211- ahb_expression_row .expression ,
198+ ahb_expression_rows .append (
199+ AhbExpression (
200+ edifact_format_version = row [0 ],
201+ format = row [1 ],
202+ expression = expression ,
203+ node_texts = node_texts ,
204+ anwendungshandbuch_primary_key = row [3 ],
205+ ahbicht_error_message = error_message ,
206+ )
212207 )
213- number_of_inserted_rows = session .scalar (
214- select (func .count (AhbExpression .id )) # type:ignore[arg-type]# pylint:disable=not-callable
215- )
208+ session .add_all (ahb_expression_rows )
209+ session .commit ()
216210 _logger .info (
217211 "Inserted %d rows into the table %s" ,
218- number_of_inserted_rows ,
212+ len ( ahb_expression_rows ) ,
219213 AhbExpression .__tablename__ ,
220214 )
221- session .commit ()
222215
223216
224217class AhbExpression (SQLModel , table = True ):
0 commit comments