On 09/19/2016 08:43 PM, Rahul Ahuja wrote:
Currently, I'm instantiating a new engine and declarative automap base
for each MySQL database I'd like to include in my session and then
individually
mapping reflected tables to the relevant engines. Some sample code to
clarify:

|
report_engine = create_engine(URL(drivername='mysql',
host='prod-mysql-analytics-master.box', port='3306',
query={'read_default_file':'/srv/db.cnf'}, database='report'))
report_base = automap_base()
report_base.prepare(report_engine, reflect=True)

md_engine = create_engine(URL(drivername='mysql',
host='prod-mysql-analytics-master.box', port='3306',
query={'read_default_file':'/srv/db.cnf'}, database='md'))
md_base = automap_base()
md_base.prepare(md_engine, reflect=True)


you can connect to no specific database and schema qualify the tables instead:


engine = create_engine("mysql://user:pass@host/")
base = automap_base(MetaData())

base.metadata.reflect(engine, schema="report")
base.metadata.reflect(engine, schema="md")

my_base.prepare()



This seems like a hack-ish approach so I'm wondering if there's a better
way. Must a separate engine and base be created for each MySQL DB?

nope

Each
DB resides on the same MySQL instance with the same host name. And must
each table be explicitly bound in the session creation?

definitely not. The SQLA docs hardly talk about "bound metadata" anywhere and I don't know where people continue to get the impression they need to do this.

Still learning
the ropes of SQLAlchemy so forgive me if these are obvious questions.
Thanks for your time!

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to