Example #1
0
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
Example #2
0
 def delete(self):
     session.delete(self)
     session.commit()
     return True
Example #3
0
 def save(self):
     session.add(self)
     session.commit()
     return True
Example #4
0
 def update_many(cls, *conditions, **set_op):
     session.query(cls).filter(*conditions).update(set_op)
     session.commit()
Example #5
0
 def execute_sql(cls, sql):
     results = session.execute(sql)
     if sql.lower().startswith('select'):
         results = list(results.fetchall())
     session.commit()
     return results