Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SQL Database #6

Open
MareoRaft opened this issue Mar 9, 2021 · 5 comments
Open

add SQL Database #6

MareoRaft opened this issue Mar 9, 2021 · 5 comments

Comments

@MareoRaft
Copy link
Owner

MareoRaft commented Mar 9, 2021

Let's make an SQL DB (maybe SQLite) and populate the stats into it, then use SQLAlchemy or pyodbc to pull the data from the database and hand it over.

@MareoRaft
Copy link
Owner Author

Let's start w/ a simple script on my local laptop.

@MareoRaft
Copy link
Owner Author

Found a good tutorial: https://riptutorial.com/sqlalchemy

And their suggested "hello world" code works:

from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, Text, MetaData, Table
from sqlalchemy import select

# globals
engine = create_engine('sqlite://')

# main
metadata = MetaData()
mytable = Table('mytable', metadata,
  Column('id', Integer, primary_key=True),
  Column('message', Text),
)
mytable.create(bind=engine)

insert_row = mytable.insert().values(message='hi, world')
engine.execute(insert_row)

statement = select([mytable.c.message])
message, = engine.execute(statement).fetchone()

print(message)

@MareoRaft
Copy link
Owner Author

Type pandas to sqlite into google and see the result!

@MareoRaft
Copy link
Owner Author

MareoRaft commented Mar 9, 2021

You can go DIRECTLY from a DataFrame to SQL using SQLAlchemy OR sqlite3 and the following method:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html

@MareoRaft
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant