Complex select instance initialization:
foo = db.foo('nick','name',age=23)
The unnamed parameters are treated as column names. If no columns
were selected for the query, the '*' (all columns) is assumed.
Named parameters
will be appended to query as conditions. All conditions must be
satisfied for every returned row.
For debugging purposes the select instance can be easily printed. The actual quoting of the values will be done by the DB-API module, especially when using unicode strings, the repr() value may not be entirely correctly quoted, but the DB-API module will take care of this.
>>> foo = db.foo('nick','name',age=23,hair='blue')
>>> print repr(foo)
< SQL: SELECT foo.nick,foo.name FROM foo WHERE ((foo.hair = 'blue') AND (foo.age = 23)) >
foo = db.foo(city='Alabama')
foo.DescOrder('age').Order('surname','name')
for row in foo:
print .....
The columns can be alternatively expressed as attributes of the
origianl select instance. If the select instance
comprises only of 1 table (no joins were performed yet), you can
access the columns of the table as attributes of the select instance.
foo = db.foo(city='Alabama') foo.DescOrder(foo.age).Order(foo.surname,foo.name)
query = db.test('name',queue='BigQueue').Order('position')[10:20]
This query provides a list of people queued in BigQueue on positions
10 to 20.
Updating can be done either using a syntax similar to the insert method, or you can directly assign to the attribute. Every assignment generates an UPDATE query to the database, if you are updating more then one column, using Update method is pereferred.db.foo().Delete()## Not a good idea..., deletes everything from table foo db.foo(userid=andrewid).Delete() ## Deletes only line with userid=andrewid
foo = db.foo(userid=andrew) foo.Update(name='YourName', address='WhereDoYouLive') # Alternativly, but it will generate 2 UPDATE queries foo.name = 'YourName' foo.address = 'WhereDoYouLive'
number_of_19_yer_old = db.foo(age=19).Count()
richness = db.foo().Sum('money')
# Alternatively by specifying column as select instance attribute
foo = db.foo()
cars = foo.Count(foo.cars)