[sqlalchemy] postgres schemas at runtime

2015-03-12 Thread Francesco Della Vedova
Hello, 

I have a set of models that I would like to replicate on different Postgres 
schemas. The name of the schema is only known at runtime. 
Just as an example, imagine I have a bunch of tables of customer data, and 
I want to create a schema 'customer_id' with the same tables every time I 
get a new customer.

I'm aware of this strategy 
https://groups.google.com/forum/#!searchin/sqlalchemy/postgres$20schemas/sqlalchemy/WDPEkqnBAXU/sYtCPFRAcvgJ
 
but it wouldn't work in my case. 

class TableA(Base):
   ...

class TableB(Base):
   ...

for customer_id in customers:
   # set the schema here
   Base.metadata.create_all()




-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] postgres schemas at runtime

2015-03-12 Thread Francesco Della Vedova
I thought about wrapping create_all this way:

def create_tables(database, schema=None):
for table in Base.metadata.tables.values():
table.schema = schema
Base.metadata.create_all(database.engine)

and then probably use the event for all the queries afterwards. Is this too 
much of a nasty way of doing it?

On Thursday, March 12, 2015 at 6:29:00 PM UTC+1, Michael Bayer wrote:



 Francesco Della Vedova francesco@rocket-internet.de javascript: 
 wrote: 

  Hello, 
  
  I have a set of models that I would like to replicate on different 
 Postgres schemas. The name of the schema is only known at runtime. 
  Just as an example, imagine I have a bunch of tables of customer data, 
 and I want to create a schema 'customer_id' with the same tables every time 
 I get a new customer. 
  
  I'm aware of this strategy but it wouldn't work in my case. 
  
  class TableA(Base): 
 ... 
  
  class TableB(Base): 
 ... 
  
  for customer_id in customers: 
 # set the schema here 
 Base.metadata.create_all() 

 you can try using table.tometadata(new_metadata, schema=my schema) to 
 make 
 new tables, and possibly even use it in conjunction with automap 
 (http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/automap.html). 

 Another approach is to use a before_cursor_execute() event, searching for 
 a 
 schema token in the SQL and rewriting it to one that is set up on the 
 current connection in the .info dictionary. 

 The latter is essentially a hacky way to get at an upcoming feature which 
 is 

 https://bitbucket.org/zzzeek/sqlalchemy/issue/2685/default-schema-schema-translation-map-as.
  


 This depends of course on if you need to use each schema on a 
 per-Session/connection basis, or you need to work with all schema-based 
 models simultaneously. 


  -- 
  You received this message because you are subscribed to the Google 
 Groups sqlalchemy group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an email to sqlalchemy+...@googlegroups.com javascript:. 
  To post to this group, send email to sqlal...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/sqlalchemy. 
  For more options, visit https://groups.google.com/d/optout. 


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Joinedload and polymorphic problem

2012-05-31 Thread Francesco
Hello everyone,
I have a big problem that alone can not solve.
There are tens of days I try to figure out how to solve this problem.
I created a little test to make you understand better.

http://pastebin.com/hdqR5P6G

I need to know the value of d.CODE with a single query on ClassA.
I need get a list of ClassA object but eager load d.CODE in
polymorphic parent.

Is there anyone who can help me?

Best regards,
Francesco

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@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.