ok, still having some sqlalchemy problems with an existing postgresql
database.

Here is what I have:

engine = create_engine('postgres://username:[EMAIL PROTECTED]:5432/
dbname', echo=True)


metadata = BoundMetaData(engine)

people_table = Table('people', metadata, autoload=True)


class People(object):
    pass

orm.clear_mappers()
mapper(People, people_table)

-----------------------------------------------

Now in the controller I have:

 dbsession = create_session(bind_to=engine)
 query = dbsession.query(People)
 p = query.get_by(username=somename)
 dbsession.close()
 return dict(people=p)

---------------------------------------------------

In my kid file I have:

........

<h2 py:for="person in people">.......


I get an error that people is not parsable.

Thanks for your patience, but I feel I'm this close to getting it
working, but can't.

On Oct 2, 5:21 pm, "Florent Aide" <[EMAIL PROTECTED]> wrote:
> On 10/3/07, vrs762 <[EMAIL PROTECTED]> wrote:
>
>
>
> > Florent,
>
> > Yes, I figured the problem. I was using an old version of SqlAlchemy.
> > Now I created a project from scratch to use SqlAlchemy and not
> > SqlObject.
>
> [...]
>
> > Now, how do I point to a preexisitng postgresql db with sqlalchemy?
>
> in your model or in an additional one, define a dburi and use it:
>
> from sqlalchemy import create_engine
> engine_ = create_engine('postgres://user:[EMAIL PROTECTED]/mydb', echo=True)
>
> Note: ideally you should store the dburi in the config file with a
> name you choose, don't stuff config values in the code, this is for
> example purposes only.
>
> then, define schema for the additional db using some distinct metadata:
>
> from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
> metadata_ = MetaData()
> some_table = Table('some', metadata_,
>     Column('id', Integer, primary_key=True),
>     ...
>
> also create a mapper for the table if you need the ORM layer...
> then, create a distinct session for your additional db:
>
> from sqlalchemy.orm import sessionmaker
> Session_ = sessionmaker(bind=engine_, autoflush=True, transactional=True)
>
> and whenever you need to use the additional db somewhere in a controller:
>
> from myapp.model import Session_
> session_ = Session_()
>
> and use this session_ instance as you would with the normal tg one to
> interact with the part of the model that are in the additional db:
>
> session_.query(Some)...
>
> Cheers,
> Florent.
>
> PS: this is just a "top of my head" info , I did not verify it nor
> test it in any way, I just typed as it came :) refinements and
> typo/bug fixes may be required ...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to