On Nov 16, 2006, at 11:31 PM, Bruno Silva wrote:

>
> On 11/16/06, Shannon -jj Behrens <[EMAIL PROTECTED]> wrote:
>>
>> I haven't used activemapper, but does this help?
>>
>> http://pylonshq.com/project/pylonshq/wiki/SqlAlchemyWithPylons
>>
>> I think the challenge is that you need to actually connect the  
>> engine,
>> and you need a dsn to do that.
>>
>
> Didn't help much, because with ActiveMapper the connection is made  
> diferently.
> And the example I show before works,... until I add a ForeignKey to
> another table, then ActiveMapper gives again the error can't find
> engine|mapper|connect
>
> I'm trying to dive in the internals, but for a python newbie is a kind
> of hard :-)
>
> I made a simple script like:
>     activemapper.metadata.connect('mysql://user:[EMAIL PROTECTED]/ 
> database')
>
>    #declare classes, like the User example
>     t = objectstore.context.current.create_transaction()
>     #do things with all classes, insert/select/update/delete
>     t.commit()
>
> everything works. But in pylons I just can't get things to work right.
> And doing the connect in every request is not the best thing to do :-)

Hi,

Maybe you can get some ideas from how TurboGears sets ActiveMapper up  
in http://tinyurl.com/yh5zeh.

In database.py (lines 21-48) the engine is configured, ActiveMapper's  
metadata is bound to it and ObjectStore is configured and bound to  
"session". This is done once when the app is loaded so I guess you  
should do something similar in your Pylons app's websetup.py and bind  
"session" to an app_global to use it in your controllers. Your tables  
should be configured with the "metadata" you just configured there  
(make sure "metadata" is configured before importing the module where  
you define your tables).

You could also edit BaseController in lib/base.py to start a new  
transaction before returning WSGIController.__call__ and wrap  
start_response to commit the transaction if no exception is raised or  
roll it back if an exception occurs.

I'm a Pylons newbie (yet, I hope...) so I'm not really sure if this  
would work, if the same technique can be applied to Pylons, or if  
it's an optimum solution; but, a-priori, I can't see why it couldn't....

BTW, I'm in the process ATM of migrating a TG app to Pylons so I  
might be able to give better advice in a few days.

HTH,

Alberto

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

Reply via email to