def save_batch(model_list, chunk_size=2000): def chunks(lst, n): for i in range(0, len(lst), n): yield lst[i:i + n] for i, chunk in enumerate(chunks(model_list, chunk_size)): session.add_all(chunk) session.commit() print(f"Epoch: {i+1}") return True
def delete(self): session.delete(self) session.commit() return True
def save(self): session.add(self) session.commit() return True
def update_many(cls, *conditions, **set_op): session.query(cls).filter(*conditions).update(set_op) session.commit()
def execute_sql(cls, sql): results = session.execute(sql) if sql.lower().startswith('select'): results = list(results.fetchall()) session.commit() return results