Skip to content

Instantly share code, notes, and snippets.

@tell-k
Created September 14, 2012 07:41
Show Gist options
  • Save tell-k/3720566 to your computer and use it in GitHub Desktop.
Save tell-k/3720566 to your computer and use it in GitHub Desktop.
# EngineをDB毎に用意
dsn1 = 'mysql://testuser:testpass@localhost/test'
engine1 = create_engine(dsn1, convert_unicode=True, echo=False)
dsn2 = 'mysql://testuser:testpass@localhost/test2'
engine2 = create_engine(dsn2, convert_unicode=True, echo=False)
Base = declarative_base()
db_session = scoped_session(sessionmaker(twophase=True))
Base.query = db_session.query_property()
# 〜〜〜 Entry, Commentテーブルの定義 〜〜〜〜
db_session.configure(binds={ # <= どのテーブルがどのDBを利用するか設定
Entry: engine1,
Comment: engine2
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment