-
Notifications
You must be signed in to change notification settings - Fork 18
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 a callback module for injecting config by other means #104
Conversation
31e18cc
to
7d7ce4f
Compare
src/sqerl_client.erl
Outdated
@@ -241,19 +212,29 @@ drivermod() -> | |||
log_and_error({invalid_application_config, sqerl, db_driver_mod, Error}) | |||
end. | |||
|
|||
%% @doc Returns the config, based on configured config_cb MFA. Defaults to | |||
%% using squerl_config_env:config/0, which will use the application environment. |
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.
sqerl_
?
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.
Of course! 😄 Thanks
src/sqerl_client.erl
Outdated
{idle_check, IdleCheck}, | ||
{prepared_statements, Statements}, | ||
{column_transforms, envy:get(sqerl, column_transforms, list)}], | ||
init(CallbackMod, Config) -> |
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.
Reading the PR I got confused because the title of the change is "callback mod" but this is the driver module, not the config one. I realize not related to this change, but wonder if a variable name change to DriverMod
would be a readability improvement.
src/sqerl_client.erl
Outdated
{prepared_statements, Statements}, | ||
{column_transforms, envy:get(sqerl, column_transforms, list)}], | ||
init(CallbackMod, Config) -> | ||
IdleCheck = proplists:get_value(idle_check, Config), |
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.
Do we handle undefined
for IdleCheck
? If not, consider verifying or crashing? Perhaps lists:keyfind
?
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've gone with a default, similar to what the record define has.
{M, F, A} = case envy:get(sqerl, config_cb, undefined, any) of | ||
undefined -> | ||
{sqerl_config_env, config, []}; | ||
{Mod, Fun, Args} = MFA when is_atom(Mod) andalso |
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 think this is probably ok since only devs are going to use the feature, but otherwise a friendlier error message when wrong type is provided would make sense. Agree?
...defaulting to what it was doing before: using envy:get/4 to fetch it from the app environment. Signed-off-by: Stephan Renatus <srenatus@chef.io>
This follows the intent of the record default value. Signed-off-by: Stephan Renatus <srenatus@chef.io>
7d7ce4f
to
220bb1c
Compare
@seth thanks for the feedback -- I've pushed another commit. Your comments got me thinking, given this behaviour of
would this case envy:get(sqerl, db_driver_mod, undefined, atom) of
undefined ->
%% ...
DriverMod when is_atom(DriverMod) ->
%% ...
Error ->
log_and_error({invalid_application_config, sqerl, db_driver_mod, Error})
end. (and that one, too) ever happen? It seems like it would need a Update Yes! Too tired! Of course it can happen in the new code, I think the new commit still makes sense, though. I'd suppose the try/catch is too defensive, since if that validation fails, we'll get a good-enough feedback. |
...defaulting to what it was doing before: using envy:get/4 to fetch
it from the app environment.