Thanks for the reply Anita.

I have an engine and things work.  I'm trying to get to the engine
object from my accounts.py file so that I can instantiate a table
object using sqlalchemy's reflection  "autoload_with=engine".  I guess
the better way to have phrased my question would have been "what do I
need to import to get to engine in my model/accounts.py file.

Perhaps your answer is correct, but if so, I don't understand it.

My goal is to have one file for each table and have an extended table
class for each table.  Then I can choose to only use the ones I want
and not have to grab every table everytime I perform an operation.

On Mar 8, 6:52 pm, akean <[email protected]> wrote:
> On Mar 9, 1:31 pm, grafman <[email protected]> wrote:
>
>
>
> > I'm new to pylons and I'm trying to use reflection to autoload my app
> > tables. I'm afraid that I've gotten my files munged up pretty badly at
> > this point but I've tried everything I can think of.  I use these
> > constructs all the time with sqlalchemy outside of pylons.
>
> > I need to bind the engine to meta data and get to it in my model files
> > (one for each table) or get directly to the engine object.  I can't
> > figure out how to do either.
>
> > My model file is account.py:
>
> > from meta import metadata
> > from sqlalchemy import Table
>
> > accounts_table = Table('accounts',metadata, autoload=True,
> > autoload_with=metadata.engine)
>
> > class Accounts(object):
> >         pass
>
> > meta.orm.mapper(Accounts,accounts_table,primary_key=[accounts_table.c.acct_id])
>
> > ==========================================
>
> > My meta.py is:from sqlalchemy import MetaData
> > from sqlalchemy.orm import scoped_session, sessionmaker
>
> > __all__ = ['Session', 'metadata']
>
> > Session = scoped_session(sessionmaker())
>
> > metadata = MetaData()
>
> > ==========================================
>
> > and my __init__.py is:"""The application's model objects"""
>
> > from sqlalchemy import orm
> > from sqlalchemy.orm import sessionmaker, scoped_session
> > from accounts.model import meta
>
> > def init_model(engine):
> >     Session.configure(bind=engine)
> >     meta.metadata.bind = engine
> >     meta.engine = engine
>
> > Thanks in advance
>
> Hi
>
> From the location of your model.py directory, look in ../config/
> environment.py  --
> down near the bottom, there's some lines:
>     # Setup the SQLAlchemy database engine
>      engine = engine_from_config(config, 'sqlalchemy.')
>      init_model(engine)
>
> This engine_from_config has docstrings which say that
> the engine takes its value from the sqlalchemy.url value assigned in
> your
> development.ini file.
> It's default value is
> # SQLAlchemy database URL
> sqlalchemy.url = sqlite:///%(here)s/development.sqlite
>
> Pass in your engine, username, etc as appropriate.
>
> Anita

-- 
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