wiki:SQLObjectQuickRef
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 1 (modified by italomaia@…, 13 years ago) (diff)

Just putting together some tips i have seem

Here you can find quick references to SQLObject, like consult examples and etc

example class:

class A(SQLObject):
    members = IntCol()
    name = StringCol(default="Annonimous",alternateID=True)
    created = DateTimeCol(default=timetime.now)
    friends = MultipleJoin("B")
    owner = ForeingKey("C")

class B(SQLObject):
    name = StringCol()

class C(SQLObject):
    name = StringCol()

Getting tuplas from database The simplest way of retrieve data from the db is as follows:

mySQLObjectClass.select()

To give it some parameters, it goes like this:

A.select(WHERE(A.q.members==10))

The WHERE if not used, is assumed, so, this would work as well:

A.select( A.q.members==10 )

It returns a group of results that fit the consult. If you want to order it by creation, do like this:

A.select( A.q.members==10, orderBy=A.q.created )

Note that the result will come sorted from older to newer. If you want it sorted from newer to older, do this:

temp = list(A.select( A.q.members==10, orderBy=A.q.created ))[::-1]

And for a limited result, the recommended is as follows:

temp = list(A.select( A.q.members==10, orderBy=A.q.created )[:10])[::-1]

If pay attention, you'll see that the slice is done to the consult result. It happens because the slicing operator is overwritten and, will work just like a limit statement in your query.

If you want to retrieve your tupla through the id, just do this:

A.get( myClassId )

To retrieve the tupla by it's primary key, just do this:

A.byName( primaryKey ) ##it may throw a SQLObjectNotFound exception