2019.05.23 - SQLAlchemy 의 객체 상태 관리 (expire, refresh, flush, commit) 에 관한 이해
SQLAlchemy에서 모델을 다루는 stage에 대해 알아보았다. Expire I've made some changes to an object and don't need it immediately but don't want any subsequent methods to use stale values. db.session.expire(Model) Refresh I've made some changes to an object and need its updated values immediately. Costs extra database call as it expires and reads from database immediately. Flush Push changes from memory to your database's transaction buffer. No database statements are issued yet. If Session has autocommit: False, must still call commit() to persist the changes or rollback() to discard changes. If Session has autocommit: True and you are not explicitly in a transaction, commit() will be automatically called. Commit Persist changes in your database's transaction buffer to the database. Database statements are issued. Automatically expires objects. Merge Used when you may have more than 1 in-memory objects which map to the same database record with some ke...