That's what .ini files are for (that thing you generated with make-
config). Search for instructions regarding sqlalchemy.dburi in a .ini
file if you want to have your connection magically setup for you and a
single database is enough.

For working with multiple databases, there's no universal best
practice. When I work with several databases, each is defined in a
different file under model/, and each gets its own Session and
metadata. Each gets a line the [app:main] section of the .ini file
like:

mydb.url = mysql://user:p...@localhost/mydb

the model/__init__.py file has an init_model() function (called from
config.environment.py:load_environment()) where I use this and other
related parameters passed in app_conf to make a session, do the
metadata.bind, Session.configure, and possibly metadata.create_all()
for each of the databases mentioned in the .ini file.

If you've got multiple databases to connect to, this init_model()
function is a natural place to initialize them all, each using a
different piece of the .ini file.

And yes, you can add your own methods to objects that derive from your
declarative base class. If you want to define some common
functionality among all these classes, put it in a plain old class
(MyBase) and pass that class to the declarative_base:
    DBBase = declarative_base(cls=MyBase, constructor=None)


On Aug 6, 7:56 am, "allen.fowler" <allen.fow...@yahoo.com> wrote:
> On Aug 5, 6:29 pm, AF <allen.fow...@yahoo.com> wrote:
>
> > Hello,
>
> > Where do you folks recommend storing the database connection string in
> > my application.  Clearly not in the same file with my declaratively
> > defined model objects.
>
> > And more generally, how do you recommend laying out an SQLAlchemy
> > based application?  (In what files to define the engine, session,
> > other objects, etc..)
>
> > Sort of looking for "best practices", I guess....
>
> > Thank you,
> > :)
>
> Anybody?
>
> Also, if using declarative base, is there any problem adding my own
> methods to the objects?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to