-
Notifications
You must be signed in to change notification settings - Fork 50
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
Allow setting custom pragmas #229
Allow setting custom pragmas #229
Conversation
00e19b4
to
0a860ba
Compare
This allows for someone to set any PRAGMA keys and values, next to the most common ones. See the documentation for a full list: https://www2.sqlite.org/draft/pragma.html One use-case is to set the `cipher_compatibility` PRAGMA which is supported by the SQLCipher extension: https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_compatibility
0a860ba
to
5087ef2
Compare
end | ||
end | ||
|
||
defp do_set_custom_pragmas(db, list) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I switched to two separate functions I tried to...
Use a case
statement, which was seen as one "indentation depth" too much by the linter.
Warning:
┃ [F] → Function body is nested too deep (max depth is 2, was 3).
┃ lib/exqlite/connection.ex:384:11 #(Exqlite.Connection.set_custom_pragma)
[13](https://github.com/elixir-sqlite/exqlite/actions/runs/3862474027/jobs/6584066856#step:9:14)
I tried a with
statement here, but that didn't work ;)
┃ [R] → `with` contains only one <- clause and an `else` branch, consider using `case` instead
┃ lib/exqlite/connection.ex:380 #(Exqlite.Connection.set_custom_pragmas)
[15](https://github.com/elixir-sqlite/exqlite/actions/runs/3862541622/jobs/6584174897#step:9:16)
So here we are with a separate function ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh credo. We should just relax it instead. I prefer readability over pedantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it was complaining about this
with {:ok, list} <- Keyword.fetch(options, :custom_pragmas) do
Enum.reduce_while(list, :ok, fn {key, value}, :ok ->
case set_pragma(db, key, value) do
:ok -> {:cont, :ok}
{:error, _reason} -> {:halt, :error}
end
end)
else
_otherwise -> :ok
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that was it, and about a nested case
statement :)
I swear I'll get to this soon. I've got another bit of work for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great.
Thank you so much! |
This allows for someone to set any PRAGMA keys and values, next to the most common ones. See the documentation for a full list: https://www2.sqlite.org/draft/pragma.html
One use-case is to set the
cipher_compatibility
PRAGMA which is supported by the SQLCipher extension:https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_compatibility
Fixes #227