On Mon, Mar 26, 2018 at 1:54 PM, Prashanth Budihal
<[email protected]> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.