On Apr 27, 2007, at 2:19 PM, 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?
you want to use a "deferred" column : http://www.sqlalchemy.org/docs/ adv_datamapping.html#advdatamapping_properties_deferred > 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. well one advantage with SA is that you can do straight SQL and get straight non-ORM results too. > > 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). yeah when you map to a select, it treats that like "a table", and selects from it so that it can be manipulated similarly. not sure why it would perform poorly, a decent optimizer should know to flatten out a basic "select to a select". > > 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. oh. well that we haven't done yet. the usual use case is that if you know the names of the columns already, why reflect them ? but yes i understand the advantage of getting the data types and foreign key constraints reflected. this wouldnt be a difficult feature to add. > 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. yeah dont do that. though its probably OK to remove columns which are not involved in any other constraints, like foreign keys, primary keys, or indexes. thats the main issue, is that the Column object is placed into various collections according to its features and if the collections are not consistent with each other errors can arise. (of course we could add comprehensive collection-altering features to Table too but id need someone to build out some great unit tests for that). > > A few other questions and comments: > > - Is there a supported way to add/remove fields from a query after > it's been constructed? from a select(), it supports adding things. there is append_column (), append_whereclause(), order_by(), etc. this API needs docstrings and probably the names "order_by/group_by" should be named "append_order_by()" etc. but you can see the methods listed out in the HTML docstrings on the site (html docs also included with the dist). removing things is not stressed so much since the typical use case is "building up" a query from a core criterion/selectable, and we have the usual issue about decisions being made based on things being appended, which to support removal would mean a lot of new code (which id welcome, of course !) to support "un-making" those decisions. > > - 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. yeah the docs have been a massive effort so at this point if things are still egregiously unclear i need some suggestions/contributions on how to better lay out things etc. ------------------------------------------------------------------------- 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