SQLObject

November 28th, 2005 § 0 comments

Sorry for the lack of posts — I’ve been out on Thanks­giv­ing vaca­tion — which allowed me to play with SQLOb­ject for some in-house projects. Bar­ring some setup problems/dependency issues I’ve had on OS/X — it rocks!

It took me a bit to wrap my head around what SQLOb­ject is meant to do, and how it would apply in my sit­u­a­tion — it’s also pointed out some very poor DB deci­sions I’ve made (I’m using it against pre-existing DBs).

Over­all, my hat goes off to Ian Bick­ing and the entire SQLOb­ject team for the tool — once I got it up and run­ning, the only bar­rier I hit was one of documentation/comprehension on my part (I hope to take some time and write up “SQLOb­ject for Morons”).

I’m going to try to type up my exact expe­ri­ences (includ­ing things I learned, and OS/X setup instruc­tions) shortly. The doc­u­men­ta­tion is good for SQLOb­ject, but I think it could be bet­ter (or maybe I’m just reading-deficient).

Vaca­tion is pretty cool — let’s me hack on things I nor­mally don’t get a chance too. Now that I think I’ve wrapped my head around SQLOb­ject (and get­ting it work­ing with my inter­nal data­bases), I think the next stop is going to be Tur­bo­Gears to write an application.

Hope­fully I can brain dump the SQLOb­ject stuff and hack on tur­bo­gears before PyCon — which I should be attend­ing (woot!).

Just thought I would add my work­ing exam­ple of SQLOb­ject Use — in this case I want to con­nect, get the results and drop the results into a list (and in a dict):

#!/usr/bin/python

from sqlob­ject import *
import os, sys

connection_string = ‘postgres://mydb@localhost/data?debug=true’
con­nec­tion = connectionForURI(connection_string)
sqlhub.processConnection = connection

class TestFiles(SQLObject):
class sql­meta:
table = ‘test­files’
from­Data­base = True # Don’t make some­thing new

# Get some test­files:
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

What's this?

You are currently reading SQLObject at jessenoller.com.

meta