From: <Ben...@ri...> - 2005-04-20 07:18:46
|
Hi, First of all I'd like to say that I really like SQLObject. It appears to be just what I need for my project. What I have is a series of API classes that contain the functionality of the application. However they are meant to be repurposable to a large number of identical "zones". At the moment this is represented as different postresql databases and schemas, e.g the same API is used on multiple sets of data. This is to allow lots of "client" sites to co-exist within one web app (yes, another case of NIH, although I feel it's justified) At the moment the code looks a bit like this: class API(object): def __init__(self, zone): class DBObj(SQLObject): _table = schema_from_zone(zone) + ".dbobj" _conn = connection_from_zone(zone) self.DBObj = DBObj Now this strikes me as a very inefficient was of doing things. I'm pretty sure construction of an SQLObject class is not trivial, and lots of these APIs are created. I could do class DBObj(SQLObject): ... class API(object): def __init__(self, zone): DBObj._table = schema_from_zone(zone) + ".dbobj" DBObj._conn = connection_from_zone(zone) But this again seems inelegant, and also not thread safe should I ever want to do that. Is there a nice way around this problem? An ideal solution would be to a clone method on the metaclass which allows each API instance to have its own objects, but they somehow share the definition. I guess another way would be to have a class outside the API with the column definitions and then inherit inside the init function to add the table and connection, but would this be any faster? Secondly I have another quick question. When you put in a ForeignKey column you actually get two properties: column and columnID. Can I rely on columnID existing into the future, as I want to use it for caching, but it appears to be undocumented at the moment. Also I have a few utility functions which I have found to be useful when using SQLObject. Would you be at all interested in including them in the distribution? Thanks for your help! Cheers, Ben |