0

I want to use my development database during testing of my flask app (it contains oauth tokens that I can't get during testing). I was hoping to be able to copy the disk based development database to memory and use that for testing so that it did not alter the development db.

so here is what I have done so far:

in my app when testing is selected use:

SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:"

Now I wish to copy my existing db into this temporary memory-based db. I have searched other answers but the closest I come is:

# open existing db
old_db = sqlite3.connect('app.db')
# get the connection to the in memory db
connection = db.get_engine().raw_connection()
# copy old_db into memory
old_db.backup(connection)

but this results in

backup() argument 1 must be sqlite3.Connection, not _ConnectionFairy

Is there a way to use the connection like this to achieve my desired aim?

Thank you

Martyn

1

1 Answer 1

1

If anyone else comes to this here's what I missed - the raw_connection() object needs to be turned into an sqlite connection by:

connection = db.get_engine().raw_connection().connection

This the full code:

# open existing db
old_db = sqlite3.connect('app.db')
# get the connection to the in memory db
conn = db.get_engine().raw_connection().connection
# copy old_db into memory
old_db.backup(conn)

Martyn

Sign up to request clarification or add additional context in comments.

Comments

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.