Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite driver does not commit data #40

Closed
lllama opened this issue Feb 22, 2023 · 1 comment · Fixed by #45
Closed

SQLite driver does not commit data #40

lllama opened this issue Feb 22, 2023 · 1 comment · Fixed by #45

Comments

@lllama
Copy link

lllama commented Feb 22, 2023

The SQLite executor does not call commit on the connection and so data is only saved for the lifetime of the application. I'm currently using Mayim with Sanic and while all new data is reflected in the application while it is running, if I quit the server then the data is lost.

(I've wrapped my inserts in a transaction but there's no difference in the behaviour).

Looking at the code, it seems only the MySQL driver explicitly calls commit on the connection.

It would be useful to be able to configure the commit behaviour. e.g. auto-commit after each query, commit at the end of a Sanic request-response cycle, explicit call a commit method on the executor, etc, etc

@lllama
Copy link
Author

lllama commented Feb 24, 2023

Just as an FYI for anyone else with this issue, I'm currently working around this with:

@app.on_response
async def commit_db(request, response):
    executor = Mayim.get(LinksExecutor)
    await executor.pool._db.commit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant