Database Functions

RESET

Truncates the entire database and clears the cache.

Warning

This will commit to the database, ALL information stored in the database WILL be lost!

Usage:

# From a model file
>>> web2py_utils.db.RESET(db, cache)

DB Rows Functions

Convenience, cross-database functions that operate on a Rows object.

These are useful if you already have your data queried, and would like to perform these statistics on them, and actually get the record that is associated with this.

MAX

Find the MAX column from rows. Returns record, max

Usage:

>>> dogs = db().select(db.dogs.ALL)
>>> oldest_dog, age = web2py_utils.db.DBRowsFunctions.MAX(dogs, 'age')

MIN

Find the MIN column from rows. Returns record, min

Usage:

>>> dogs = db().select(db.dogs.ALL)
>>> youngest_dog, age = web2py_utils.db.DBRowsFunctions.MIN(dogs, 'age')

AVG

Find the AVG column from rows. Returns avg

Usage:

>>> dogs = db().select(db.dogs.ALL)
>>> average_age = web2py_utils.db.DBRowsFunctions.AVG(dogs, 'age')

SUM

Find the SUM column from rows. Returns sum

Usage:

>>> dogs = db().select(db.dogs.ALL)
>>> total_age = web2py_utils.db.DBRowsFunctions.SUM(dogs, 'age')

Table Of Contents

Previous topic

Auth Patches

Next topic

Menu

This Page