how to get sql dump of a database created in sqlite using sqlalchemy

后端 未结 1 2009
不知归路
不知归路 2021-01-23 16:03

I have data read from json and fed into an sqlite database with proper schema using sql-alchemy in python. (used pd.dataframe.to_sql() for this). I want the database dump (.sql

1条回答
  •  伪装坚强ぢ
    2021-01-23 16:30

    Assuming that you have a SQLAlchemy engine object associated with your SQLite database you can simply use Python's iterdump method like so:

    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)
    

    0 讨论(0)
提交回复
热议问题