On Jun 27, 2008, at 12:23 PM, Petr Dlabal wrote:

>
> I don't understand how can remote client application have the same
> mapper setup in situation where there is no direct connection to
> database to reflect the tables and map to the classes.
> In addition at the server side the classes are declared only like
> class XYZ(object):pass and the internal structure of the class is
> created from reflected (autoload) tables.
> Maybe I missed something, but I think, that I need the engine
> connected to database and then metadata to map the classes and get
> their internal structure (from reflected (autoload) tables) - but the
> client side cannot connect to database.
> I don't know what means "declarative" extension. This is the part of
> the mapping code at server side:
>
> class KLASS(object):pass
> class SUBKLASS(object):pass
> class SUBSUBKLASS(object):pass
>
> table_T = Table('table', metadata,autoload = True)
> subtable_T = Table('subtable', metadata,autoload = True)
> subsubtable_T = Table('subsubtable', metadata, autoload = True)
>
> mapper(KLASS,table_T,properties={'atr':relation(SUBKLASS,lazy=False)})
> mapper
> (SUBKLASS
> ,subtable_T,properties={'subatr':relation(SUBSUBKLASS,lazy=False)})
> mapper(SUBSUBKLASS,subsubtable_T)
>
> So, I don't understand how to repeat this definitions at client side
> if there is no database connection (no metadata etc.)
>
> Thank you very much, btw SQLAlchemy is great, although I'm not
> programmer so I have never seen any ORM before :-)

theres a module that defines your classes.  Any application that  
wishes to use these classes, including your client, must import this  
module in order for Pickle to work.  But when you instrument those  
classes with a toolkit like SQLAlchemy, the module that defines your  
classes is not enough; you must additionally define a module that  
creates Table/mappers as well, and applies itself in the same way.     
Since you're using autoload=True, this would imply a database  
connection on both sides, but if that's not an option, you can either  
not use autoload=True, or you can serialize the MetaData object itself  
into a file (using Pickle again) and load it up in your client.   
pickle.dumps(metadata) specifically is made to work for this reason.   
One way or another, since the shape of your database is determining  
the shape of your classes, that information needs to get sent over to  
the client in some way, preferably in the same way that the class  
definitions themselves are available (i.e. as a module level metadata  
= pickle.loads(mymetadata.txt)).

The "declarative" extension, which may be helpful but is orthogonal to  
the issue of "autoload=True" here, is described at 
http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative 
  .









>
>
> Peter
>
> On Fri, Jun 27, 2008 at 3:56 PM, Michael Bayer <[EMAIL PROTECTED] 
> > wrote:
>>
>>
>> On Jun 27, 2008, at 3:25 AM, Nabla wrote:
>>
>>>
>>> Is there some easy solution of this problem?
>>
>> yes, the receiving application needs to have the same mapper() setup
>> as the sender.   If you use the "declarative" extension to setup your
>> classes, this task is made easier.
>>
>>>
>>> And additional question - is there some "simple" way how to
>>> "convert" (marshal, serialize) reflected sqlalchemy class to "human-
>>> readable" XML?
>>
>> we dont have an XML serializer but there might be something on Pypi
>> for that.
>>
>>>
>>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to