[sqlalchemy] Re: SA ORM Tutorial: Query

2009-02-26 Thread Michael Bayer


On Feb 26, 2009, at 12:40 AM, a.fowler wrote:


 Hello,

 A couple of questions on the tutorial:

 1) Why .all() in 3rd (and some others) query code box, but not
 others?

.all() is essentially equivalent to list(query).   Some of the  
examples already iterate the query, such as  for x in query: print x,  
others don't - but the tutorial wants you to see the results. 
Ideally none of the examples would use all() since you generally  
iterate to get results.



 2) Filter clause:  Why  '==' vs. '=' used in .filter() vs. .filter_by
 ()

the argument signature of filter() is:

filter(argument)

whereas that of filter_by() is:

filter_by(**kwargs)

the argument is a clause expression.   SQLAlchemy generates clause  
expressions when you call overridden Python operators like ==  
(__eq__()) and similar.  The SQL expression tutorial spends a little  
more time on this concept.

 3) Common Filter Operators: Why or_(), and_(), in_(), but like().
 (instead of like_() )

or/and/in are Python reserved words, it's convention per pep8 to  
rename functions/variables with a trailing underscore if they conflict.

 4) Common Filter Operators: Is '!= None' the correct way to get a NOT
 NULL? (Not mentioned in tutorial)

that will work yes

 5) Common Filter Operators: Using User.name.match raised an
 (OperationalError) unable to use function MATCH in the requested
 context... why?  (using sqlite:memory is per tutorial)

MATCH is not supported by every database, SQLite is apparently one of  
them.  I'm a little surprised that operator found its way into the  
tutorial since I've never used it



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SA ORM Tutorial: Query

2009-02-26 Thread a.fowler


  A couple of questions on the tutorial:

  1) Why .all() in 3rd (and some others) query code box, but not
  others?

 .all() is essentially equivalent to list(query).   Some of the
 examples already iterate the query, such as  for x in query: print x,
 others don't - but the tutorial wants you to see the results.
 Ideally none of the examples would use all() since you generally
 iterate to get results.


Ah OK.

   Why or_(), and_(), in_(), but like().
  (instead of like_() )

 or/and/in are Python reserved words, it's convention per pep8 to
 rename functions/variables with a trailing underscore if they conflict.


I see.


  4) Common Filter Operators: Is '!= None' the correct way to get a NOT
  NULL? (Not mentioned in tutorial)

 that will work yes

  5) Common Filter Operators: Using User.name.match raised an
  (OperationalError) unable to use function MATCH in the requested
  context... why?  (using sqlite:memory is per tutorial)

 MATCH is not supported by every database, SQLite is apparently one of
 them.  I'm a little surprised that operator found its way into the
 tutorial since I've never used it

Thank you.  A very clear explanation.  :)


I don't know if the docs team reads this, but here are a couple of
comments:

1)  Perhaps re-emphasize, in a few more places, SA's overloading of
the logical operators. I had forgotten that by the time I got to the
query filter section.

2) Since there are two alternative paths to take take in the class /
table building part (mapper / declarative), it not clear what the
prerequisites are for the 2nd path. To fix this, please show resetting
the python interpreter after the mapper example, and re-importing all
that is actually needed for the declarative version.

3) Mention the right way to filter by NOT NULL.

4) Mention the reservedword_() naming convention in passing.  It
should be known to Python programmers, but since this is a tutorial,
it could be there are new Python users here as well.

5) Since the tutorial actually shows using SQLite, mention that
the .match() directive is not supported by SQLite.

I hope to finish the tutorial over the next few days, and may have
more comments then.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SA ORM Tutorial: Query

2009-02-26 Thread Michael Bayer


On Feb 26, 2009, at 11:49 AM, a.fowler wrote:


 I don't know if the docs team reads this, but here are a couple of
 comments:

I'm pretty much the documentation team :).but my time is very  
short these days, would you be interested in submitting a patch  
against the documentation source file ?   It's written in ReST format  
and can be found in the distribution/current trunk in doc/build/ 
ormtutorial.rst .   I can quickly review your patches and integrate  
them with the current documentation.   the docs can also be built if  
you type make html in that directory.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---