One more vote that it's absolutely worth learning SA even if you're an sql whiz. It's a superb library, and let's you operate at multiple levels of abstraction. And great sql injection insurance!
iain On Sun, Feb 20, 2011 at 8:39 AM, Ben Bangert <b...@groovie.org> wrote: > On Feb 20, 2011, at 1:58 AM, AwaisMuzaffar wrote: > > > Thanks for the reply guys it has been very informative. > > > > My main reason for using raw is that I have spent so much time > > learning MySQL, to me it seems counter productive to learn SQLALchemy > > methodologies from scratch. > > > > Ok, so maybe manually executing CREATE is not a great idea, but what > > about performing queries with pure MySQL, is that fine? > > The main utility I've found in SQLAlchemy is its connection pooling, > automatic reconnection, and the fact that dynamically generating queries by > concatenating raw SQL inside text strings is pretty horrendous. After using > SQLAlchemy for awhile, I've finally gotten to the point where its actually > easier for me to now write many SQLAlchemy queries than to use the raw SQL. > Of course, as was mentioned, you do need to know the raw SQL to be able to > tell SQLAlchemy how to do the right thing anyways. > > I'd say its worth the hassle of learning the abstraction purely for the > ability to easily dynamically generate queries. Concatenating text strings > of raw SQL is very error-prone. > > An example of dynamically generating an SQLAlchemy query in a model > instance method: > > cases = meta.Session.query(cls) > if court: > cases = cases.filter_by(court_id=court) > elif ecf: > cases = cases.filter_by(ecf_abbreviation=ecf) > cases = cases.filter(cls.filed_on>=datetime(2000,1,1)) > if judge: > cases = cases.filter(cls.id.in_(judge_case_ids(judge))) > > It's quite easy to dynamically build up the filter conditions, dynamically > include additional table joins as needed, etc. > > Cheers, > Ben > > -- > You received this message because you are subscribed to the Google Groups > "pylons-devel" group. > To post to this group, send email to pylons-devel@googlegroups.com. > To unsubscribe from this group, send email to > pylons-devel+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/pylons-devel?hl=en. > > -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-devel@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.