Thu, 10 Aug 2006

Using sqlobject in cherryPy

from sqlobject import *

conn = 'mysql://dbuser:dbpass@host/dbname'

class NameOfTable(SQLObject):
    _connection = conn
    _fromDatabase = True
    _style = MixedCaseStyle(longID=False)

class Newspage(Page):
    def index(self):
        article = NameOfTable.select(NameOfTable.q.field=='Joe', orderBy=-NameOfTable.q.dateAdded)


Notes:
    _fromDatabase = True means sqlobject will simply take column names from
    the DB.  It won't create any, which it is capable of doing.

    MixedCaseStyle - sqlobject uses pythonic names like my_name.  This allows
    the use of names like myName.

    longID=False - prevents sqlobject from automatically creating an ID column

    - in front of NameOfTable.q.dateAdded means reverse sort

Posted at: 21:38 | category: /database | Comments ()