13 messages in com.googlegroups.sqlalchemy[Sqlalchemy-users] Objects with just ...
FromSent OnAttachments
Mike Orr27 Apr 2007 11:19 
Kapil Thangavelu27 Apr 2007 11:28 
Michael Bayer27 Apr 2007 11:34 
Mike Orr27 Apr 2007 16:58 
HD Mail08 May 2007 03:55 
Mike Orr08 May 2007 17:47 
Michael Bayer08 May 2007 21:07 
Mike Orr09 May 2007 11:14 
Mike Orr09 May 2007 11:45 
Michael Bayer09 May 2007 12:13 
Mike Orr09 May 2007 20:49 
Mike Orr22 May 2007 15:16 
Michael Bayer22 May 2007 18:18 
Subject:[Sqlalchemy-users] Objects with just some fields
From:Mike Orr (slug@gmail.com)
Date:04/27/2007 11:19:34 AM
List:com.googlegroups.sqlalchemy

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".

When I brought this up previously (in a read-only context), somebody suggested mapping a Select rather than a Table. That worked but it led to "select of select" or "select of select of select", which performed considerably worse than building a query dynamically (by calling a function to to create the query and set the field list, and then calling .append_whereclause several times).

What I'd like to do is pass a list of column names to the Table constructor and have it autoload those and ignore the others. I couldn't find an argument for this. Alternatively I could autoload the table and then delete the undesired columns via a list comprehension, but it looks like that would involve modifying private attributes with possibly unintended consequences.

A few other questions and comments:

- Is there a supported way to add/remove fields from a query after it's been constructed?

- The .scalar() method of query results is incredibly useful but poorly documented. It's shown in a few examples in the manual but not explained. I added ticket #549 for it, and just now saw zzzeek's comment requesting wording explaining both that and the entire ResultProxy class, so I'll work on that.