Skip to content

Instantly share code, notes, and snippets.

@youssefeldakar
Created September 12, 2019 09:35
Show Gist options
  • Save youssefeldakar/1a3de47c39995d855a8cfe24c9726edf to your computer and use it in GitHub Desktop.
Save youssefeldakar/1a3de47c39995d855a8cfe24c9726edf to your computer and use it in GitHub Desktop.
Python: SQLAlchemy db access example
#!/usr/bin/python
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
Base = automap_base()
engine = create_engine('mysql://rmanalyzer:42c718i1@localhost/redmine')
Base.prepare(engine, reflect=True)
session = Session(engine)
q = session.query(Base.classes.issue_statuses)
print(q.count())
# vim: ts=4: sts=4: sw=4:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment