Re: [sqlalchemy] Re: Accessing multiple databases with same schema

2010-12-16 Thread g3 N
Thanks for the idea posted.
I shall try this too.

Thanks,
Gayatri

On Fri, Dec 3, 2010 at 11:25 PM, Eric N elmkne...@gmail.com wrote:

 I had a similar issue that I resolved by creating a set_data_model
 function that when I called in it would set some global variable to
 the table objects based on the product passed in to the function.  I'm
 using multiple schemas in a Postgres database and wanted to try to
 limit the number of connections and this was the best way to do that.
 The other benefit is that none of my external scripts need to know
 anything about the schemas or keeping track of different sessions. The
 basic idea is shown below.

 Table1 = None
 table1_table = None
 Table2 = None
 table2_table = None

 def set_data_model(product):
  global Table1
  global table1_table
  global Table2
  global table2_table
  if product == 'A':
Table1 = productA.Table1
table1_table = productA.table1_table
Table2 = productA.Table2
table2_table = productA.table2_table
  if product == 'B':
...


 On Dec 2, 11:28 am, g3 N tunetog3...@gmail.com wrote:
  Thanks for the suggestions.
  I'll try them.
 
  Thanks,
  Gayatri
 
  On Thu, Dec 2, 2010 at 8:19 PM, Nagy Viktor viktor.n...@toolpart.hu
 wrote:
   I would say that if no connection between the databases are required
 then
   two sessions are pretty fine.
   e.g no query like db1.table1 join db2.table2 exists
 
   otherwise, it might still work to use one session by importing/definig
 your
   table classes twice, and adding all of them to your session with
   Session.configure(binds={db1.table1: engine1, db2.table1: engine2})
 
 On Thu, Dec 2, 2010 at 3:29 PM, gayatri tunetog3...@gmail.com
 wrote:
 
Hello All,
 
   We have a client-server application. On server side we have two
   databases with same set of tables.
 
   Based on the client request, server has to get data from the
   corresponding database.
 
   So, in this scenario, I would like to know which of the following
   approaches is better?
 
   1.To have two sessions and have a lookup based on the client request.
 
   2.Have a single session and use sharding.
 
   Thanks,
   Gayatri
 
   --
   You received this message because you are subscribed to the Google
 Groups
   sqlalchemy group.
   To post to this group, send email to sqlalch...@googlegroups.com.
   To unsubscribe from this group, send email to
   sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
 sqlalchemy%2bunsubscr...@googlegroups.comsqlalchemy%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/sqlalchemy?hl=en.
 
   --
   You received this message because you are subscribed to the Google
 Groups
   sqlalchemy group.
   To post to this group, send email to sqlalch...@googlegroups.com.
   To unsubscribe from this group, send email to
   sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
 sqlalchemy%2bunsubscr...@googlegroups.comsqlalchemy%252bunsubscr...@googlegroups.com
 
.
   For more options, visit this group at
  http://groups.google.com/group/sqlalchemy?hl=en.

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Accessing multiple databases with same schema

2010-12-03 Thread Eric N
I had a similar issue that I resolved by creating a set_data_model
function that when I called in it would set some global variable to
the table objects based on the product passed in to the function.  I'm
using multiple schemas in a Postgres database and wanted to try to
limit the number of connections and this was the best way to do that.
The other benefit is that none of my external scripts need to know
anything about the schemas or keeping track of different sessions. The
basic idea is shown below.

Table1 = None
table1_table = None
Table2 = None
table2_table = None

def set_data_model(product):
  global Table1
  global table1_table
  global Table2
  global table2_table
  if product == 'A':
Table1 = productA.Table1
table1_table = productA.table1_table
Table2 = productA.Table2
table2_table = productA.table2_table
  if product == 'B':
...


On Dec 2, 11:28 am, g3 N tunetog3...@gmail.com wrote:
 Thanks for the suggestions.
 I'll try them.

 Thanks,
 Gayatri

 On Thu, Dec 2, 2010 at 8:19 PM, Nagy Viktor viktor.n...@toolpart.hu wrote:
  I would say that if no connection between the databases are required then
  two sessions are pretty fine.
  e.g no query like db1.table1 join db2.table2 exists

  otherwise, it might still work to use one session by importing/definig your
  table classes twice, and adding all of them to your session with
  Session.configure(binds={db1.table1: engine1, db2.table1: engine2})

    On Thu, Dec 2, 2010 at 3:29 PM, gayatri tunetog3...@gmail.com wrote:

   Hello All,

  We have a client-server application. On server side we have two
  databases with same set of tables.

  Based on the client request, server has to get data from the
  corresponding database.

  So, in this scenario, I would like to know which of the following
  approaches is better?

  1.To have two sessions and have a lookup based on the client request.

  2.Have a single session and use sharding.

  Thanks,
  Gayatri

  --
  You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

  --
  You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.