1

I am looking to increase an entire column's values by a certain variable amount, and initially I used sqlite3, but in order to optimise my script I had to switch to SQLAlchemy, but I am unable to find similar utilities in SQLAlchemy. For example, for sqlite3 I did this:

amt = 3 #for example

with sqlite3.connect("funds.db") as con:
    cur = con.cursor()
    cur.execute("UPDATE funds_table SET funds=funds+?", (int(amt),))
    con.commit()

Basically, for a column of 3,4,5 for example, it would increase to 6,7,8. I have searched but can't find a way to do this through SQLalchemy, other than manually iterating through each row (?) which seems inefficient.

Justin Chee
  • 427
  • 1
  • 3
  • 14

1 Answers1

0

Okay, at first I didn't know what to do with this post, but then I realised what to do. Adapting the code from the post, I end up with:

Funds.query.update({Funds.funds: Funds.funds+amt}) 
db.session.commit()
Justin Chee
  • 427
  • 1
  • 3
  • 14