I wanted to process the already generated table, and when I tried to manage the session of the reflected table with SQLAlchemy, it got strange, so I summarized it. In the end, all you have to do is use automap_base ().
I don't understand scralchemy at all, so I welcome you to point out.
--mac (OS X El Capitan version 10.11.5)
session.py
# -*- coding: utf-8 -*-
import sys
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import sessionmaker
def main(sys_argv):
# MAMP + Mysql-How to generate an engine in Python environment
engine = sqlalchemy.create_engine(
"mysql://user_name:password@localhost/db_name"
+ "?unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock",
echo=False)
#Session start
session = sessionmaker(bind=engine)()
#Generate a mapped instance using reflection
base = automap_base()
base.prepare(engine, reflect=True)
#Do what you want to do
# your_table delete from table_If you want to display id with flag 0
your_table = base.classes.your_table
result = session.query(your_table).filter(delete_flag == 0)
for row in result:
print row.id
#End of session
session.close()
if __name__ == '__main__':
main(sys.argv)
Recommended Posts