Re: [sqlalchemy] How to create multiple TABLES and INSERTS programatically ?

2018-03-31 Thread Prashanth Budihal
Hello testing my messages are being deleted

On Tuesday, March 27, 2018 at 12:12:51 AM UTC+5:30, Mike Bayer wrote:
>
> On Mon, Mar 26, 2018 at 1:54 PM, Prashanth Budihal 
>  wrote: 
> > I have this project(stock market data) where I need many tables(200+) 
> and 
> > each one will receive fresh data inserts periodically(every 5 minutes). 
> I 
> > have gone thru couple of tutorials about sqlalchemy ORM and they all 
> show 
> > how to create a single table and do few inserts. But if I have to create 
> > 200+ tables then should I create/type manually 200+ mapped classes ? 
> Thats 
> > impractical isnt it ? I face same hurdle while doing INSERTS.  Can 
> anybody 
> > here give me a hint atleast how to go about this ? Which part of 
> sqlalchemy 
> > addresses this hurdle. I admit I am a newbie to sql and sqlalchemy so 
> please 
> > bear with me if there is already a solution and I havent studied it yet. 
> > Thanks in advance. 
>
> Python is a fully dynamic language so if you needed 200 classes given 
> a list of 200 names, you would never have to "type" that manually. 
> However if this is a really simple case then just use core: 
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), Column('q', Integer), Column('p', 
> Integer), ... ) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> something like that. 
>
> if these tables have all kinds of different columns you can reflect them: 
>
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), autoload_with=conn) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> but you need to know what the columns are that you are inserting. 
>
>
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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 . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] How to create multiple TABLES and INSERTS programatically ?

2018-03-31 Thread Prashanth Budihal
For the benefit of others visiting this page. This is another way to do it. 
Uses Class type 
https://stackoverflow.com/questions/2768607/dynamic-class-creation-in-sqlalchemy

On Tuesday, March 27, 2018 at 12:12:51 AM UTC+5:30, Mike Bayer wrote:
>
> On Mon, Mar 26, 2018 at 1:54 PM, Prashanth Budihal 
>  wrote: 
> > I have this project(stock market data) where I need many tables(200+) 
> and 
> > each one will receive fresh data inserts periodically(every 5 minutes). 
> I 
> > have gone thru couple of tutorials about sqlalchemy ORM and they all 
> show 
> > how to create a single table and do few inserts. But if I have to create 
> > 200+ tables then should I create/type manually 200+ mapped classes ? 
> Thats 
> > impractical isnt it ? I face same hurdle while doing INSERTS.  Can 
> anybody 
> > here give me a hint atleast how to go about this ? Which part of 
> sqlalchemy 
> > addresses this hurdle. I admit I am a newbie to sql and sqlalchemy so 
> please 
> > bear with me if there is already a solution and I havent studied it yet. 
> > Thanks in advance. 
>
> Python is a fully dynamic language so if you needed 200 classes given 
> a list of 200 names, you would never have to "type" that manually. 
> However if this is a really simple case then just use core: 
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), Column('q', Integer), Column('p', 
> Integer), ... ) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> something like that. 
>
> if these tables have all kinds of different columns you can reflect them: 
>
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), autoload_with=conn) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> but you need to know what the columns are that you are inserting. 
>
>
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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 . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] How to create multiple TABLES and INSERTS programatically ?

2018-03-31 Thread Prashanth Budihal

>
> @Mike Bayer
>
> I thought I will post here an alternate solution.
> https://stackoverflow.com/questions/2768607/dynamic-class-creation-in-sqlalchemy
>  
>  
>

On Tuesday, March 27, 2018 at 12:12:51 AM UTC+5:30, Mike Bayer wrote:
>
> On Mon, Mar 26, 2018 at 1:54 PM, Prashanth Budihal 
>  wrote: 
> > I have this project(stock market data) where I need many tables(200+) 
> and 
> > each one will receive fresh data inserts periodically(every 5 minutes). 
> I 
> > have gone thru couple of tutorials about sqlalchemy ORM and they all 
> show 
> > how to create a single table and do few inserts. But if I have to create 
> > 200+ tables then should I create/type manually 200+ mapped classes ? 
> Thats 
> > impractical isnt it ? I face same hurdle while doing INSERTS.  Can 
> anybody 
> > here give me a hint atleast how to go about this ? Which part of 
> sqlalchemy 
> > addresses this hurdle. I admit I am a newbie to sql and sqlalchemy so 
> please 
> > bear with me if there is already a solution and I havent studied it yet. 
> > Thanks in advance. 
>
> Python is a fully dynamic language so if you needed 200 classes given 
> a list of 200 names, you would never have to "type" that manually. 
> However if this is a really simple case then just use core: 
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), Column('q', Integer), Column('p', 
> Integer), ... ) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> something like that. 
>
> if these tables have all kinds of different columns you can reflect them: 
>
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), autoload_with=conn) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> but you need to know what the columns are that you are inserting. 
>
>
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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 . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] How to create multiple TABLES and INSERTS programatically ?

2018-03-31 Thread Prashanth Budihal
For the benefit of other visitors to this page,another solution I found.
https://stackoverflow.com/questions/2768607/dynamic-class-creation-in-sqlalchemy

On Tuesday, March 27, 2018 at 12:12:51 AM UTC+5:30, Mike Bayer wrote:
>
> On Mon, Mar 26, 2018 at 1:54 PM, Prashanth Budihal 
>  wrote: 
> > I have this project(stock market data) where I need many tables(200+) 
> and 
> > each one will receive fresh data inserts periodically(every 5 minutes). 
> I 
> > have gone thru couple of tutorials about sqlalchemy ORM and they all 
> show 
> > how to create a single table and do few inserts. But if I have to create 
> > 200+ tables then should I create/type manually 200+ mapped classes ? 
> Thats 
> > impractical isnt it ? I face same hurdle while doing INSERTS.  Can 
> anybody 
> > here give me a hint atleast how to go about this ? Which part of 
> sqlalchemy 
> > addresses this hurdle. I admit I am a newbie to sql and sqlalchemy so 
> please 
> > bear with me if there is already a solution and I havent studied it yet. 
> > Thanks in advance. 
>
> Python is a fully dynamic language so if you needed 200 classes given 
> a list of 200 names, you would never have to "type" that manually. 
> However if this is a really simple case then just use core: 
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), Column('q', Integer), Column('p', 
> Integer), ... ) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> something like that. 
>
> if these tables have all kinds of different columns you can reflect them: 
>
>
> my_twohundred_names = [   ... names ] 
>
> with engine.connect() as conn: 
> for name in my_twohundred_names: 
> t = Table(name, MetaData(), autoload_with=conn) 
> conn.execute(t.insert(), {"q": 5, "p": 10}) 
>
> but you need to know what the columns are that you are inserting. 
>
>
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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 . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-31 Thread Serhii Mozghovyi
Many thanks!

On Wednesday, March 28, 2018 at 6:42:16 PM UTC+3, Mike Bayer wrote:
>
> the backrefs intentionally don't keep fanning deep into object graph 
> for this kind of thing, so if you want it to go one hop further you 
> can add an event to do that directly: 
>
> from sqlalchemy import event 
> from sqlalchemy.orm import attributes 
>
>
> @event.listens_for(Address.user, "set") 
> def _intercept_set(target, value, oldvalue, initiator): 
>
> if isinstance(oldvalue, User) and "address" in oldvalue.__dict__: 
> attributes.set_committed_value(oldvalue, "address", None) 
>
>
> the "set_committed_value" is to avoid triggering any new events which 
> will cause a recursion overflow. 
>
>
>
> On Wed, Mar 28, 2018 at 10:49 AM, Serhii Mozghovyi  > wrote: 
> > Is it possible to make child objects (many-to-one side) delete itself 
> from 
> > the old parent's collection when it is added to a different parent? 
> > See the file attached. The old parent remains unaware that he doesn't 
> have 
> > this child anymore. 
> > 
> > P.S. session.expire() is an obvious solution but too heavy. I expect 
> some 
> > event-based collection synchronization, much like backref 
> (back_populates) 
> > connected collections. 
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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 . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.