Migración de SQLObject a SQLAlchemy :: ¿Puede SQLAlchemy admitir el almacenamiento en caché cero y las actualizaciones de tabla de carga automática?

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?

Gracias de antemano por la ayuda.

preguntado el 31 de enero de 12 a las 08:01

Based on what I know about SQL in general, the SQLObject framework must have been doing the equivalent of session.merge() on every object you loaded under the covers (which may have been wasteful); and now with SQLAlchemy, you have to choose whether to do it explicitly or not for each transaction. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.