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

Add read only mode #214

Merged
merged 7 commits into from
Apr 9, 2024
Merged

Add read only mode #214

merged 7 commits into from
Apr 9, 2024

Conversation

pedroripper
Copy link
Member

This PR allows the user to load a database in "Read only" mode.

Currently, we have two dispatches for PSRI.load_study, one that applies a migration first (if needed), and another that just loads the database.

When applying a migration, the database should not be in "Read only" mode, so for the second dispatch, I have added a boolean parameter (default = false) that sets the loading mode.

So when a user uses

db = PSRI.load_study(PSRI.PSRDatabaseSQLiteInterface(), database_path; read_only = true)

they can only perform reading queries and cannot modify the database.

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.93%. Comparing base (818605d) to head (662fcda).
Report is 1 commits behind head on master.

❗ Current head 662fcda differs from pull request most recent head 5f4a551. Consider uploading reports for the commit 5f4a551 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #214   +/-   ##
=======================================
  Coverage   82.93%   82.93%           
=======================================
  Files          37       37           
  Lines        4226     4226           
=======================================
  Hits         3505     3505           
  Misses        721      721           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guilhermebodin
Copy link
Member

I think that when we use load_db it is also worth it to set a busy timeout.

Comment on lines 10 to +12
sqlite_db = SQLite.DB(database_path)

DBInterface.execute(sqlite_db, "PRAGMA busy_timeout = 5000;")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a good idea to create a function here to wrap this repeated code.

@guilhermebodin guilhermebodin merged commit ebd81b0 into master Apr 9, 2024
8 checks passed
@guilhermebodin guilhermebodin deleted the pr/sql-read-only branch July 5, 2024 18:08
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 this pull request may close these issues.

2 participants