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