SQLObject

by jesse in ,


Sorry for the lack of posts - I've been out on Thanksgiving vacation - which allowed me to play with SQLObject for some in-house projects. Barring some setup problems/dependency issues I've had on OS/X - it rocks! It took me a bit to wrap my head around what SQLObject is meant to do, and how it would apply in my situation - it's also pointed out some very poor DB decisions I've made (I'm using it against pre-existing DBs).

Overall, my hat goes off to Ian Bicking and the entire SQLObject team for the tool - once I got it up and running, the only barrier I hit was one of documentation/comprehension on my part (I hope to take some time and write up "SQLObject for Morons").

I'm going to try to type up my exact experiences (including things I learned, and OS/X setup instructions) shortly. The documentation is good for SQLObject, but I think it could be better (or maybe I'm just reading-deficient).

Vacation is pretty cool - let's me hack on things I normally don't get a chance too. Now that I think I've wrapped my head around SQLObject (and getting it working with my internal databases), I think the next stop is going to be TurboGears to write an application.

Hopefully I can brain dump the SQLObject stuff and hack on turbogears before PyCon - which I should be attending (woot!).

Just thought I would add my working example of SQLObject Use - in this case I want to connect, get the results and drop the results into a list (and in a dict):

#!/usr/bin/python

from sqlobject import * import os, sys

connection_string = 'postgres://mydb@localhost/data?debug=true' connection = connectionForURI(connection_string) sqlhub.processConnection = connection

class TestFiles(SQLObject): class sqlmeta: table = 'testfiles' fromDatabase = True # Don't make something new

# Get some testfiles: testfile_results = TestFiles.select(TestFiles.q.testsuite==_mysuite)

t_file_data = [ i.file for i in testfile_results ]

mydict = {} for i in testfile_results: mydict[i.testsuite] = i.file

print t_file_data