Re: [SQLObject] Getting Started with SQLObject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2005-10-24 22:37:19
|
David Pratt wrote: > Hi there. I am new to SQLObject. I am concerned that I don't repeat my > work so it is best to ask a few questions first. > > 1. What is the best way to organize a project with SQLObject. I was > thinking of a base.py that would contain connection and base classes and > then a separate file for each class representing a table with its > methods. Any guidance here would be appreciated. I usually put all classes in a module named db. I sometimes use an abstract superclass, but usually not. Using sqlhub is generally an easier/better way to manage the connection, like sqlobject.sqlhub.processConnection = sqlobject.connectionForURI('...') But I generally don't put that in db.py, since then I've hardcoded my database connection. sqlobject-admin likes a Paste Deploy-style configuration file (http://pythonpaste.org/deploy/), which mostly just means: [app:main] database = database_uri (You pass this in with -f) However, specifying the configuration in all the contexts you want it can be a little challenging, and I don't have any complete solution. > 2. I also do work in Zope although presently in zope2, I am beginning to > work in Five. SQLOS uses this type of strategy for the schema. In all > the examples shown on the SQLObject site, you are using something like > this: > > >>> class Person(SQLObject): > ... > ... firstName = StringCol() > ... middleInitial = StringCol(length=1, default=None) > ... lastName = StringCol() > > in SQLOS, this is desired: > > _columns = [StringCol('username', length=20, notNull=True), > StringCol('fname', length=20, notNull=True), > StringCol('lname', length=20, notNull=True),] > > I would like to do things just once so schemas will not have to be > changed whether or not I use Zope. Can the _columns type arrangement be > used directly by SQLObject? If so, can you explain. I think the sqlos docs must be a bit old; this was a (quite) old form for SQLObject classes. I think you can use the more modern technique now of attributes for columns (which should be completely equivalent). -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |