Mike Orr wrote: > Is it possible to make a mapper class that loads & modifies only some > fields in a table rather than all the fields, yet still autoloads the > fields rather than having hardcoded column types? I've been avoiding > the ORM because frequenty I want to iterate every record without > loading some large text fields, and to avoid 20-line SELECTS in the > log which make debugging less convenient. Yet now I have a > data-conversion project and have been charmed at the ability to load > an object, modify and flush it, without having to do "SELECT" + > "UPDATE ... WHERE" If this is a batch type process you are undertaking and will be doing repeatedly, don't succumb to the temptation of using ORM. Your performance will suffer. Especially if you are doing things like auto inserting parent - child objects with auto increment keys in the child. I did a recent batch import script using SA ORM and although it worked perfectly, the performance was lacking. This of course is not SA's fault but it was just a case of choosing the right tool for the right job. It was a breeze to change all my ORM code to using SA sql though, so it wasn't a big deal. I used a convenience method to create my insert statements so it was almost like my ORM code. so instead of session.save(obj), I had:
def get_columns(table, o): result = {} for c in table.c: if hasattr(o, c.name): val = getattr(o, c.name) if val is not None: result[c.name] = val return result my_table.insert().execute(**get_columns(my_table, my_object)) The ORM is misleadingly simple (especially if you go berzerk with relations). Because I tend to go berzerk with joins, it's straight SA SQL all the way for me. For batch stuff, it was a killer when SA pre-fetched all the database default values. eg. "select local_timestamp()", "select nextval('')" for every single row. Huy SA.Fan ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users