Last active
March 13, 2017 02:36
-
-
Save dodo5522/78f234aa7945a3b81528dfa8330ea70a to your computer and use it in GitHub Desktop.
SQLAlchemy + PyMySQLでのデータ取得方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import sqlalchemy as sa | |
if __name__ == "__main__": | |
engine = sa.create_engine( | |
"mysql+pymysql://{USER}:{PASS}@{HOST}/{DB}?charset=utf8".format( | |
USER=sys.argv[1], PASS=sys.argv[2], HOST=sys.argv[3], DB=sys.argv[4])) | |
ret = engine.execute("select account.id, account.name_, ability.detail from account inner join ability on account.id = ability.user_id where ability.detail regexp '.*子.*';") | |
dat = ret.fetchall() | |
print(dat[:5]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment