Re: [SQLObject] thoughts on structure and components
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Ian B. <ia...@co...> - 2003-05-15 16:04:51
|
On Thu, 2003-05-15 at 10:57, Bud P.Bruegger wrote:
> > Declaring a connection for a class is easy. Why is it a problem?
>
> It is easy once you know. When I first used it, I didn't understand
> why it wouldn't work and found out that I need the connection first.
> At least for me personally, decoupling connection and definition of
> the physical representation makes it easier to use, flattens the
> learning curve.. But I may be alone on this...
Then that might just be a documentation issue.
> > The other way would be to make a table-driven columnsFromSchema that was
> > attached to your connection, and let that create the columns for you.
>
> If I understand this correctly, ie, that you store the "object schema"
> that defines the mapping from python to SQL in tables, it comes very
> close to how I do it. Just that I am at a level where I represent the
> mapping as python objects--but it would be possible to write them out
> to a dbms and get them back into an object form..
Well, I was thinking of something that's maybe a bit more hackish.
Like:
class MappingPostgresConnection(PostgresConnection):
def __init__(self, mappings=None, **kw):
self.mappings = mappings
PostgresConnection(self, **kw)
def columnsFromSchema(self, table, soClass):
return self.mappings[soClass.__name__]
myConnection = MappingPostgresConnection(
mappings={'Person': [Col('name'), ...],
'PhoneNumber': [Col(...)]}
Ian
|