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 [email protected]
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