Michael Bayer wrote:
because all the keyword arguments to select_by are taken as the names of properties. if select_by had order_by, limit, etc. it would have to look like;

x = m.select_by({'name':'jack', 'address':'[EMAIL PROTECTED]'}, order_by=addresses.c.id, limit=10)

which we can do, of course.  what do you think ?

Ahhh..thanks for clearing that up.

I actually prefer your previous example i.e

result = usermapper.select_by(address='[EMAIL PROTECTED]').order_by(addresstable.c.address)[4:15]

This seems to facilitate a much more flexible style of building select statements, rather then passing these things as parameters.
It would be nice to make the select() also using this style.
so building selects can be

s = select([users])
if order_by_address:
   s.order_by(addresstable.c.address)
else:
   s.order_by(user.c.id)
s.limit(5)
curs = s.execute()

Do we really want to use that slicing [] syntax though ? I tend to switch to SQL mode when writing queries in SA, so SQL keyword functions like order_by, limit(limit, offset=None), having(), for_update() etc. would make much more sense. Using specific python syntax for this single case just feels inconsistent.

Just MO so feel free to ignore.

Regards,

Huy

On May 11, 2006, at 3:46 AM, HD Mail wrote:

Michael Bayer wrote:
As theres a lot of clamor for this lately, FYI to those looking for a more flexible "select_by". the SelectResults extension can give you a lot of what youre looking for.

    from sqlalchemy.ext.selectresults import SelectResultsExt

    addressmapper = mapper(Address, addresstable)
usermapper = mapper(User, usertable, properties={'addresses':addressmapper}, ext=SelectResultsExt())

result = usermapper.select_by(address='[EMAIL PROTECTED]').order_by(addresstable.c.address)[4:15]

will add "LIMIT 4 OFFSET 15 ORDER BY addresses.address" to the generated query before executing.

Sorry, I haven't been keeping up with any previous discussions so my question may
already be answered, but is there a reason why select_by is
working different to .select(limt=4, offset=15).

Without know the answer to my first question, this just seems confusing because there'd be two different methods for specifying limit/offset/order by.

Huy



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to