summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/sqlsoup.py
diff options
context:
space:
mode:
authorJonathan Ellis <jbellis@gmail.com>2006-10-05 16:27:33 +0000
committerJonathan Ellis <jbellis@gmail.com>2006-10-05 16:27:33 +0000
commit24c29b9ae77b18124ecfeae2021e94c6b319b66e (patch)
tree2f04f2269c4a0193e8d1da3a0736222eed1a3e95 /lib/sqlalchemy/ext/sqlsoup.py
parent8b1afef6e92199691f250213042166bfcbd5d024 (diff)
downloadsqlalchemy-24c29b9ae77b18124ecfeae2021e94c6b319b66e.tar.gz
add compound-where example
Diffstat (limited to 'lib/sqlalchemy/ext/sqlsoup.py')
-rw-r--r--lib/sqlalchemy/ext/sqlsoup.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py
index b8aaf2fa5..be772555d 100644
--- a/lib/sqlalchemy/ext/sqlsoup.py
+++ b/lib/sqlalchemy/ext/sqlsoup.py
@@ -41,8 +41,15 @@ Field access is intuitive:
>>> users[0].email
u'student@example.edu'
-Of course, you don't want to load all users very often. The common case is to
-select by a key or other field:
+Of course, you don't want to load all users very often. Let's add a WHERE clause.
+Let's also switch the order_by to DESC while we're at it.
+ >>> from sqlalchemy import or_, and_, desc
+ >>> where = or_(db.users.c.name=='Bhargan Basepair', db.users.c.email=='student@example.edu')
+ >>> db.users.select(where, order_by=[desc(db.users.c.name)])
+ [MappedUsers(name='Joe Student',email='student@example.edu',password='student',classname=None,admin=0), MappedUsers(name='Bhargan Basepair',email='basepair@example.edu',password='basepair',classname=None,admin=1)]
+
+You can also use the select...by methods if you're querying on a single column.
+This allows using keyword arguments as column names:
>>> db.users.selectone_by(name='Bhargan Basepair')
MappedUsers(name='Bhargan Basepair',email='basepair@example.edu',password='basepair',classname=None,admin=1)