[SQLObject] Legacy databases convenience class
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: David M. <da...@re...> - 2004-02-05 01:52:19
|
Hi, I'm a total newcomer to SQLObject, having finally chosen it from the n other 'SQL-db-as-python-object' wrappers. I had originally vetoed SQLObject because it appeared to *require* classes to be declared to mimic existing databases. But on reading a bit deeper in the doco, and coming across the magic '_fromDatabase' attribute, I came up with a convenience layer (attached) for opening up and working with existing databases (well, databases that already have an 'id' index column. Quick look at what it does: >>> import sqlobj >>> db = sqlobj.mysqlobj(db='test', user='test', passwd='test') >>> print db.tables ['address', 'people'] >>> addr = db.address >>> print addr.columns ['street', 'suburb', 'city', 'phone'] >>> pps = db.people.select() >>> for p in pps: print p <people 1 first='fred' last='daggg' age=34L> <people 2 first='mary' last='smith' age=27L> <people 3 first='adam' last='jones' age=42L> <people 4 first='jane' last='doe' age=35L> Before developing it any further, I thought to post here what I've done, so that people might: 1) advise if anything similar, preferably better, has already been done (urls please) 2) advise on any pitfalls my approach might suffer Lastly, thanks to SQLObject devs for a fine layer. It's the missing piece in my (yet another) python web framework www.freenet.org.nz/python/pyweb Cheers David -- leave this line intact so your email gets through my junk mail filter |