Fixes #329. Support automatic database routing.