Permalink
Browse files

update the select() to show what it returns, so that the documentatio…

…n is more complete.
  • Loading branch information...
1 parent 091f572 commit 9fb28c5571a73d9ca43f742402b6c2ad5d9796ff @peacetara committed Feb 3, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 web/db.py
View
14 web/db.py
@@ -673,6 +673,20 @@ def select(self, tables, vars=None, what='*', where=None, order=None, group=None
<sql: 'SELECT * FROM foo'>
>>> db.select(['foo', 'bar'], where="foo.bar_id = bar.id", limit=5, _test=True)
<sql: 'SELECT * FROM foo, bar WHERE foo.bar_id = bar.id LIMIT 5'>
+
+
+ Return an iterator of storage items. example:
+ db.query("create table foo (age int, name varchar(30), created datetime);")
+ db.insert("INSERT INTO foo (age, name, created) VALUES (2, 'bob', NOW())")
+ r = db.select('foo')
+ r is now an iterator or you can get by item:
+ r[0] is the first row returned.
+ r[0].age == 2
+ r[0].name == 'bob'
+ r[0].created is the timestamp for whatever NOW() is at the time of insert.
+
+ len(r) gives you the rowcount, in this case 1.
+
"""
if vars is None: vars = {}
sql_clauses = self.sql_clauses(what, tables, where, group, order, limit, offset)

2 comments on commit 9fb28c5

@aaronsw

I think we should probably a) refer to web.query and put this there, b) write it as an actual doctest.

@peacetara
Owner

I've never written a doctest before, I've always done nose/unittest type testing. My understanding is doctests are executable code, but we don't have a DB to execute against I would imagine. I guess I'll have to figure out how you do it for your other tests.

as for #1, you are right about db.query and a reference.

Please sign in to comment.