title: Multiple Mappers for the same class in different databases
body: <p>I am currently working on a Wikipedia API which means that we have a
  database for each language we want to use. The structure of each
  database is identical, they only differ in their language. The only
  place where this information is stored is in the name of the database.</p>
  
  <p>When starting with one language the straight forward approach to use a
  mapping between the tables to needed classes (e.g. Page) looked fine.
  We defined an engine and corresponding metadata. When we added a
  second
  database with its own setup for engine and metadata we ran into the
  following error:</p>
  
  <pre><code>ArgumentError:
  Class '&lt;class 'wp.orm.types.pages.Page'&gt;' already has a primary mapper defined.
  Use non_primary=True to create a non primary Mapper.clear_mappers() will remove
  *all* current mappers from all classes.
  </code></pre>
  
  <p>I found an <a href="http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg08221.html" rel="nofollow noreferrer">email saying that there must be at least one primary
  mappe</a>r, so using this option for all databases doesn't seem feasible.</p>
  
  <p>The next idea is to use sharding. For that we need a way to
  distinguish
  between the databases from the perspective of an instance, as <a href="http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/sharding/attribute_shard.py" rel="nofollow noreferrer">noted in
  the docs</a>:</p>
  
  <blockquote>
    <p>"You need a function which can return
    a single shard id, given an instance
    to be saved; this is called
    "shard_chooser"</p>
  </blockquote>
  
  <p>I am stuck here. Is there a way to get the database name given an
  Object
  it is loaded from? Or a possibility to add a static attribute based on
  the engine? The alternative would be to add a language column to every
  table which is just ugly.
  Am I overseeing other possibilities? Any ideas how to define multiple
  mappers for the same class, that map against tables in different
  databases?</p>