On Tue, Aug 25, 2009 at 10:08 AM, Jonathan Vanasco<[email protected]> wrote: > > I've come to that point in a Pylons app myself -- SqlAlchemy has > become too much of a hassle for anything other than some basic add/ > edit on records, and I'm migrating all of my pages to use custom data > structures that can be cached and manipulated better. Pylons, and > even SA, are pretty awesome in being able to let me do that sort of > stuff.
This may not directly relate to what you're saying, but there are several ways to organize a model. (1) Put just the raw ORM definitions in the model. The Pylons tutorials do this. (2) Add class methods to the ORM objects for high-level selection. You can take this to the extreme with magic properties. (3) Make a database-neutral layer with a SQLAlchemy backend. So if the interface "returns an iterable of objects with read-only attributes", the actual objects can be ORM, SQL rowproxies, or objects from a different database. SQLAlchemy objects are mainly for database I/O, so there may be good reasons to copy the data into other structures for everyday use and caching. One major advantage of SQLAlchemy is the SQL level, which is several times faster than the ORM for making bulk changes. This feature is mentioned in passing but perhaps it should be emphasized more in Pylons marketing. SQLAlchemy is not "just an ORM" like the others. I have found the ORM useful in the following cases: - Retrieve an object and modify it with the least amount of fuss. - Add-or-modify an object that may or may not exist. - Looping through lots of objects when you don't care if the process takes a long time. The SQL level is more useful for: - Looping through 1+ million records in a read-only manner. - Inserting many records that you know do not exist yet. - Bulk changes that can be done in a single statement. (Set all X field to 0, or add 5 to the current value.) - Modifying the table structure in place. -- Mike Orr <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
