
你尝试过普拉克吗?
docs中的示例:
# dbcli.pyimport placfrom sqlalchemy.ext.sqlsoup import SqlSoup@plac.annotations( db=plac.Annotation("Connection string", type=SqlSoup), header=plac.Annotation("Header", 'flag', 'H'), sqlcmd=plac.Annotation("SQL command", 'option', 'c', str, metavar="SQL"), delimiter=plac.Annotation("Column separator", 'option', 'd'), scripts=plac.Annotation("SQL scripts"), )def main(db, header, sqlcmd, delimiter="|", *scripts): "A script to run queries and SQL scripts on a database" yield 'Working on %s' % db.bind.url if sqlcmd: result = db.bind.execute(sqlcmd) if header: # print the header yield delimiter.join(result.keys()) for row in result: # print the rows yield delimiter.join(map(str, row)) for script in scripts: db.bind.execute(open(script).read()) yield 'executed %s' % scriptif __name__ == '__main__': for output in plac.call(main): print(output)输出:
usage: dbcli.py [-h] [-H] [-c SQL] [-d |] db [scripts [scripts ...]]A script to run queries and SQL scripts on a databasepositional arguments: db Connection string scripts SQL scriptsoptional arguments: -h, --help show this help message and exit -H, --header Header -c SQL, --sqlcmd SQL SQL command -d |, --delimiter | Column separator
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)