I want to know if SQLAlchemy can support instant loading of the current state of an object from the database when another process updates some attributes of the same object.
I want to mention, I am migrating from SQLObject to SQLAlchemy. Using SQLObject, currently, I have one table like:
class MyConfiguration(SQLObject):
class sqlmeta:
cacheValues = False
attr1 = StringCol(default='')
attr2 = IntCol(default=0)
As you know, this cacheValues=False setting instantly flushes attribute updates to the disk:
global my_config
my_config = MyConfiguration()
my_config.attr1 = 'some value'
The instant attr1 is set to 'some value', that value is available to another process using the same object my_config.
I have gone through the basic tutorial's of SQLAlchemy's ORM and Core and as I understand, the nearest I can go to achieve this is by using session.merge() because unless I add or merge, the state of "my_config" in SQLAlchemy will not become pending/dirty and with autoflush=True, the subsequent querying will re-read the row from the table.
Another option I thought was I could over-ride setattr in MyConfiguration to flush changes to an instance instantly. However, I don't like this because this is ugly and I want to use as much SQLAlchemy's features as possible than me hacking something.
So I am trying to find an exact match of this SQLObject's feature in SQLAlchemy. Is this possible?
Thanks in advance for the help.