How to connect two or more db by boss_db?

70 views
Skip to first unread message

jiale.chan

unread,
Mar 18, 2014, 11:30:53 PM3/18/14
to chica...@googlegroups.com
Hi,

I have tow mysql db,

How to connect two or more database by boss_db?

Nicholas Whittier

unread,
Mar 19, 2014, 1:37:17 PM3/19/14
to chica...@googlegroups.com
Use db_shards in boss config.

....
 {db_shards, [
        [{db_host, "localhost"},
         {db_adapter, pgsql},
         {db_port, 5432},
         {db_username, "pg_user"},
         {db_password, "pg_pass"},
         {db_database, "pg_db"},
         {db_shard_id, shard_pg},
         {db_shard_models, [some_postgres_model,another_postgres_model]}],
[{db_host, "mysql.example.com"},
         {db_adapter, mysql},
         {db_port, 3306},
         {db_username, "my_user"},
         {db_password, "my_pass"},
         {db_database, "my_db"},
         {db_shard_id, shard_my},
         {db_shard_models, [some_mysql_model,another_mysql_model]}]
...

Note that you can still use the default db setting (mock, via mnesia) to handle sessions and boss-specific db needs.

-- Nicholas

Alexey Marunin

unread,
Mar 19, 2014, 3:39:52 PM3/19/14
to chica...@googlegroups.com
Nicholas,

This is just what I need!

Few questions:
1) What for need value of db_shard_id? Only for internal usage in mysql/postgres/... or I should use it explicitly?
2) Can I use "cross-db" models? Something like this:

SiteUser: Id, Name -> db1
ForumUser: Id, SiteUserId -> db2

Is valid call:

user = forum_user:site_user()


среда, 19 марта 2014 г., 21:37:17 UTC+4 пользователь Nicholas Whittier написал:

Nicholas Whittier

unread,
Mar 19, 2014, 9:25:02 PM3/19/14
to chica...@googlegroups.com


On Wednesday, March 19, 2014 12:39:52 PM UTC-7, Alexey Marunin wrote:
Nicholas,

This is just what I need!

Few questions:
1) What for need value of db_shard_id? Only for internal usage in mysql/postgres/... or I should use it explicitly?

It must be an atom, and afaik boss_db uses it and you shouldn't need to worry about it.
 
2) Can I use "cross-db" models? Something like this:


Since shards can be different databases (mongo vs. mysql OR mysql1 vs. mysql2), I woudn't think you could relate the models from two different db shards via Boss_DB's relationships. Relationships are managed in the db_adapter and as far as CB knows, each db shard is using it's own adapter. I haven't needed or tried this, maybe someone else can chime in with other suggestions?
 
-- Nicholas
Reply all
Reply to author
Forward
0 new messages