On Dec 5, 2004, at 1:20 PM, Ian Bicking wrote:
>>>
>>> I have successfully been using SQLObject svn trunk for a few days
>>> now, without modifications. I have implemented automatic class
>>> generation by reading information from the database about classes
>>> and their columns and joins. I did this by extending MetaSQLObject
>>> with my own behavior, and a factory method called
>>> getClass(classname), which checks the registry, and then constructs
>>> a new class if the registry does not contain the proper class.
>
> This sounds very similar to ezSqlObject, except it uses __getattr__ to
> create the classes (e.g., db.User, instead of getClass('user')).
yes, it would be similar.
>
>>> The problem I am running into now, is when you have joined classes,
>>> the joined classes have to be explicitly loaded. In your
>>> users/roles example, my code would have to look something like this:
>>> userClass = getClass('user')
>>> roleClass = getClass('role') #if this is not called here, user.roles
>>> will not be defined, because the role class is not in the registry
>>> user = userClass.get(1)
>>> print list(user.roles[0])
>
> So you are creating the joins dynamically as well? How does that
> work? How lazy do you need the class creation to be?
Yes, I am creating the joins dynamically, which creates the problem
that I don't know which classes are going to join to other non-existent
classes. I don't care about lazy, my only problem is that the python
code that is written will not know which child/grandchild classes will
need to exist.
>
> I notice there's no .tables() method on connections, just
> .tableExists() -- it's a pretty no-brainer that such a method should
> exist, returning a list of strings. Would that be enough? Then you
> could create all the classes at startup.
If the answer from the SQLObject team is to create them up front, I am
willing to do that. I would just rather not.
>
>>> It would great if the registry was allowed to have a factory method
>>> set to attempt automatic class creation if the class does not exist.
>>> If I coded this up as a patch, would it be accepted?
>
> I'm not entirely clear what you are thinking. Right now the registry
> tracks classes, but it never returns classes. Instead class
> references are pushed into the places they are needed, using callbacks
> which are triggered on class creation. So I'm not sure where this
> would fit.
The registry always returns a class when asked (for classes in joins,
etc), or am I just smoking something??? I understand it never
generates a class.
Scott
|