Re: I'm lost with ActiveMapper
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 -~--~~~~--~~--~--~---
I'm lost with ActiveMapper
Hi there, I tried SQLAlchemy and ActiveMapper. And now I'm learning Pylons framework, and I would like to use ActiveMapper. I can' t really tell you how much configurations I tried. I found one that works, but I think perhaps It's not the best practice. I tried to do the connection in every place I could think off, and I always had the error about the engine no bound. So I did the worst case, doing it in the BaseController, and to know if the connection is always made in every request, I simple print a message. What I found is that it prints the message about 10 messages, and then activemapper is always bound. I don't know why that happens, connection pools? I'm a bit lost here, because I'm new to python/pylons/sqlaclhemy, I hope if someone can point me in the right direction. thanks in advance, Bruno models/__init__.py--- from sqlalchemy import * from sqlalchemy.ext.activemapper import * from datetime import datetime class User(ActiveMapper): class mapping: __table__ = 'lemmings_sysuser' username= column(String(15)) name= column(String(60)) password= column(String(50)) email = column(String(50)) status = column(Integer) created = column(DateTime) last_login = column(DateTime) lib/base.py--- ... import sqlalchemy.ext.activemapper as activemapper class BaseController(WSGIController): def __call__(self, environ, start_response): if not activemapper.metadata.is_bound(): print activemapper not bound from paste.deploy import CONFIG config = CONFIG['app_conf'] dsn = config.get('dsn') if not dsn: raise KeyError('No database uri found!') activemapper.metadata.connect(dsn) return WSGIController.__call__(self, environ, start_response) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: I'm lost with ActiveMapper
On 11/16/06, Bruno Silva [EMAIL PROTECTED] wrote: I tried SQLAlchemy and ActiveMapper. And now I'm learning Pylons framework, and I would like to use ActiveMapper. I can' t really tell you how much configurations I tried. I found one that works, but I think perhaps It's not the best practice. I tried to do the connection in every place I could think off, and I always had the error about the engine no bound. So I did the worst case, doing it in the BaseController, and to know if the connection is always made in every request, I simple print a message. What I found is that it prints the message about 10 messages, and then activemapper is always bound. I don't know why that happens, connection pools? I'm a bit lost here, because I'm new to python/pylons/sqlaclhemy, I hope if someone can point me in the right direction. thanks in advance, Bruno models/__init__.py--- from sqlalchemy import * from sqlalchemy.ext.activemapper import * from datetime import datetime class User(ActiveMapper): class mapping: __table__ = 'lemmings_sysuser' username= column(String(15)) name= column(String(60)) password= column(String(50)) email = column(String(50)) status = column(Integer) created = column(DateTime) last_login = column(DateTime) lib/base.py--- ... import sqlalchemy.ext.activemapper as activemapper class BaseController(WSGIController): def __call__(self, environ, start_response): if not activemapper.metadata.is_bound(): print activemapper not bound from paste.deploy import CONFIG config = CONFIG['app_conf'] dsn = config.get('dsn') if not dsn: raise KeyError('No database uri found!') activemapper.metadata.connect(dsn) return WSGIController.__call__(self, environ, start_response) 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. Please forgive my ignorance if I'm way off base. Best Regards, -jj -- http://jjinux.blogspot.com/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---