4

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 file) of this database. is there any api in sql alchemy that would do this?

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

3 Comments

The iterdump referenced here is an sqlite3 function.
Is there any agnostic SQL alchemy function to generate a SQL dump from a database connection?
Just a note, it should be f.write('%s/n' % line) as \n is not a special character.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.