我有从json读取的数据,并使用python中的sql-alchemy以适当的模式输入到sqlite数据库中。(为此使用pd.dataframe.to_sql())。我想要此数据库的数据库转储(.sql文件)。在SQL Alchemy中有没有可以做到这一点的API?
假设您有一个engine
与SQLite数据库关联的SQLAlchemy对象,则可以简单地使用Python的iterdump方法,如下所示:
con = engine.raw_connection()
with open('C:/Users/Gord/Desktop/dump.sql', 'w') as f:
for line in con.iterdump():
f.write('%s\n' % line)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句