How to connect to 2 databases at the same time?

1 view
Skip to first unread message

Mike Kent

unread,
Mar 21, 2007, 10:36:17 PM3/21/07
to SQLElixir
Actually, I have two questions I'd appreciate some help on.

1. Using Elixir, how do I connect to two different databases at the
same time? I can see that I need two different metadata instances,
and somehow have to associate the right metadata instance with the
right tables, but I don't see how yet. An example of how to do this
would be great.

2. I'd like to use 'use_options(autoload=True)' with several tables
in an existing database, where the tables have pre-existing
relationships. I know that Elixir is supposed to handle this, and
generate the relationships on the Entity class instances. How do I
know what names Elixir has assigned to both ends of the relationship
between two tables?

__wyatt

unread,
Mar 22, 2007, 3:15:16 PM3/22/07
to SQLElixir
On Mar 21, 7:36 pm, "Mike Kent" <mrmak...@cox.net> wrote:
> Actually, I have two questions I'd appreciate some help on.
>
> 1. Using Elixir, how do I connect to two different databases at the
> same time? I can see that I need two different metadata instances,
> and somehow have to associate the right metadata instance with the
> right tables, but I don't see how yet. An example of how to do this
> would be great.

You'd probably also need two ``engine``s (one per DB). Then, assuming
your ``metadata``s are dynamic you'd do this:

metadata_1.connect(engine_1)
metadata_2.connect(engine_2)

Or you could use ``BoundMetaData``s and bind them to your ``engine``s
up front and not need call ``connect``.

Elixir ships with a default ``DynamicMetaData`` (elixir.metadata), but
you don't have to use it. You can create your own ``metadata``s and
then use ``using_options(metadata=my_metadata)`` when declaring your
``Entity``s.

Hope that helps a little,

__wyatt

Mike Kent

unread,
Mar 22, 2007, 8:00:42 PM3/22/07
to SQLElixir
On Mar 22, 3:15 pm, "__wyatt" <wyatt.lee.bald...@gmail.com> wrote:
> On Mar 21, 7:36 pm, "Mike Kent" <mrmak...@cox.net> wrote:
> You'd probably also need two ``engine``s (one per DB). Then, assuming
> your ``metadata``s are dynamic you'd do this:
>
> metadata_1.connect(engine_1)
> metadata_2.connect(engine_2)
>
> Or you could use ``BoundMetaData``s and bind them to your ``engine``s
> up front and not need call ``connect``.
>
> Elixir ships with a default ``DynamicMetaData`` (elixir.metadata), but
> you don't have to use it. You can create your own ``metadata``s and
> then use ``using_options(metadata=my_metadata)`` when declaring your
> ``Entity``s.
>
> Hope that helps a little,

Actually, that helps a lot. Thanks.

Gaetan de Menten

unread,
Mar 23, 2007, 4:27:16 AM3/23/07
to sqle...@googlegroups.com
On 3/22/07, Mike Kent <mrma...@cox.net> wrote:
>
> Actually, I have two questions I'd appreciate some help on.

> 2. I'd like to use 'use_options(autoload=True)' with several tables


> in an existing database, where the tables have pre-existing
> relationships. I know that Elixir is supposed to handle this, and
> generate the relationships on the Entity class instances. How do I
> know what names Elixir has assigned to both ends of the relationship
> between two tables?

I think you are mistaken. Elixir supports autoloaded tables, but
doesn't generate relationships between tables. See

http://elixir.ematia.de/svn/elixir/trunk/tests/test_autoload.py

for an example.

By the way, the autoload feature is still a bit experimental. In
version 0.2.0, it doesn't support has_and_belongs_to_many
relationships. Many improvements were made in the trunk but it's still
not quite perfect (it fails on self-referencial
has_and_belongs_to_many relationships).
--
Gaëtan de Menten
http://openhex.org

Reply all
Reply to author
Forward
0 new messages