I'm trying to load a dictionary into a Postgres database via SQLAlchemy in Python. The dictionary as it current exists is:
FinalData = {'GAME_ID': {0: '0021600457', 1: '0021600457', 2: '0021600457', 3:
'0021600457', 4: '0021600457', 5: '0021600457'}, 'TEAM_ID': {0: 1610612744, 1:
1610612744, 2: 1610612744, 3: 1610612744, 4: 1610612744, 5: 1610612744},
'TEAM_ABBREVIATION': {0: 'GSW', 1: 'GSW', 2: 'GSW', 3: 'GSW', 4: 'GSW', 5:
'GSW'}}
I have the following code written (based off other tutorials/questions I've found here and online). I could make this work if I was only inserting 1 records - since I could manually assign the attribute to PlayerStats. But with the dictionary having multiple records, I don't know how to bulk pass them all onto the session statements.
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
Base = declarative_base()
class PlayerStats(Base):
__tablename__ = 'PlayerStats'
GAME_ID = Column(String(10), primary_key=True)
TEAM_ID = Column(String(10))
TEAM_ABBREVIATION = Column(String(8))
###################################################
## I DON'T KNOW WHAT GOES HERE TO BRIDGE THE GAP ##
###################################################
engine = create_engine('postgres://.........')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
session.add(FinalData) # I'M ASSUMING I NEED TO ITERATE OVER THIS #
I'm sure I'm missing something simple, but how do I pass all contents of the FinalData dictionary onto the SQLAlchemy add statement?