Skip to content

Instantly share code, notes, and snippets.

@wannadrunk
Created March 17, 2022 03:18
Show Gist options
  • Save wannadrunk/dc139ab5cf907f07362306cf57d805f9 to your computer and use it in GitHub Desktop.
Save wannadrunk/dc139ab5cf907f07362306cf57d805f9 to your computer and use it in GitHub Desktop.
SAMPLE SQLAlchemy connect to existing DB/Tables
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, MetaData, Table
# Using SQLAlchemy reflection example
engine = create_engine('connectionstringhere')
table1meta = MetaData(engine)
table1 = Table('Table_I_Want_to_Interact', table1meta, autoload=True)
DBSession = sessionmaker(bind=engine)
session = DBSession()
results = session.query(table1).filter(table1.columns.TimeStamp>="2019-02-26 18:00:00.000")
results.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment