Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Allow esqlite’s timeout to be specified #65

Merged
merged 2 commits into from
May 28, 2018

Conversation

marramgrass
Copy link
Contributor

Hello.

First, thank you for the library. It's come in very useful for us.

We've been doing some work where we needed to increase the timeout esqlite applies to various operations. This pull request updates Sqlitex to expose the timeout argument in the various places that esqlite does so.

With these changes, Sqlitex defaults to the esqlite timeout of 5000 ms, and uses a combination of default values on the function arguments and implementing an Application-level config to leave the interface of Sqlitex unchanged for those who don't need to modify the timeout.

I think this is a broadly useful enough change to consider bringing into the upstream, but I worry that the implementation is a little noisy. Please let me know any changes you want made.

Thanks again.

@sourcelevel-bot
Copy link

Hello, @marramgrass! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

{:ok, result, new_cache} -> {:reply, {:ok, result}, {db, new_cache}}
err -> {:reply, err, {db, stmt_cache}}
def handle_call({:query, sql, opts}, _from, {db, stmt_cache, timeout}) do
case query_impl(sql, opts,stmt_cache, timeout) do

Choose a reason for hiding this comment

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

Space missing after comma

lib/sqlitex.ex Outdated
@spec close(connection) :: :ok
def close(db) do
:esqlite3.close(db)
@esqlite3_timeout Application.get_env(:sqlitex, :esqlite3_timeout, 5_000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I could be wrong, but doesn't storing this in a module attribute mean that this gets read from the app config at compile time? So if I update the :esqlite3_timeout in my config but don't explicitly recompile sqlitex then that change won't be picked up?

I guess maybe Elixir is smart enough to pick up that the change in sqlitex config might require a sqlitex recompile, but I'm not sure if that is the case...

Copy link
Contributor Author

@marramgrass marramgrass May 18, 2018

Choose a reason for hiding this comment

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

You know, I'm not sure either.

If we went with changing these to use keyword lists anyway then the intended benefit of using module attributes (easy specification of default values in function definitions) is no longer needed.

Thanks 👍

lib/sqlitex.ex Outdated
def open(path) do
:esqlite3.open(path)
@spec open(charlist | String.t, integer()) :: {:ok, connection} | {:error, {atom, charlist}}
def open(path, timeout \\ @esqlite3_timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure, but would it be better to expose these parameters as keyword list? That way if we need to add other options we can just add new keywords rather than needing to add a whole new parameter...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I think it would be preferable. Will update accordingly.

@mmmries
Copy link
Collaborator

mmmries commented May 20, 2018

@marramgrass thank you for this PR. I think that allowing the timeout to be passed through is a great idea and doing it with optional keyword options, then an Application config and finally a hardcoded default is a great idea. Thanks for your work on this.

@marramgrass
Copy link
Contributor Author

For info, I will be coming back to this to update. Just very busy with other things at the moment. Sorry for the delay.

@mmmries
Copy link
Collaborator

mmmries commented May 25, 2018

@marramgrass thanks for letting us know. I'm happy to wait for you to make the changes, or if you'd like some help I can take some time to make those changes myself.

lib/sqlitex.ex Outdated
:esqlite3.open(path)
@spec open(charlist | String.t, Keyword.t) :: {:ok, connection} | {:error, {atom, charlist}}
def open(path, opts \\ [])
def open(path,opts) when is_binary(path), do: open(string_to_charlist(path), opts)

Choose a reason for hiding this comment

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

Space missing after comma

@marramgrass
Copy link
Contributor Author

I've pushed a further commit making the discussed changes.

Please let me know if you'd rather I squashed them down to one.

Also changed to use :db_timeout as the key in most places,
for brevity. Retained :esqlite3_timeout in the Application env.
@mmmries mmmries merged commit 10eeb21 into elixir-sqlite:master May 28, 2018
@marramgrass marramgrass deleted the esqlite-timeouts branch May 28, 2018 16:22
@mmmries
Copy link
Collaborator

mmmries commented May 28, 2018

Thanks @marramgrass for this contribution. I think I'll change the name of the global config to match the db_timeout name. I'll try to get a release out today.

@mmmries
Copy link
Collaborator

mmmries commented May 28, 2018

Got 1.4.0 released with your changes included. Thank you again!

@marramgrass
Copy link
Contributor Author

Thank you @mmmries and @obmarg for making my first contribution to the project such a pleasant and smooth experience 👍

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

Successfully merging this pull request may close these issues.

3 participants