Skip to content

Commit

Permalink
update the select() to show what it returns, so that the documentatio…
Browse files Browse the repository at this point in the history
…n is more complete.
  • Loading branch information
peacetara committed Feb 3, 2012
1 parent 091f572 commit 9fb28c5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web/db.py
Expand Up @@ -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)
Expand Down

2 comments on commit 9fb28c5

@aaronsw
Copy link

@aaronsw aaronsw commented on 9fb28c5 Feb 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@peacetara
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 webpy#1, you are right about db.query and a reference.

Please sign in to comment.