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

Fix up from_query docs #822

Merged
merged 2 commits into from
Jan 15, 2024
Merged

Fix up from_query docs #822

merged 2 commits into from
Jan 15, 2024

Conversation

cigrainger
Copy link
Member

@cigrainger cigrainger commented Jan 15, 2024

The examples for DataFrame.from_query show from_query/2, but this isn't defined. Params need to be passed, even if empty.

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

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

At the time, we chose to require the parameters to avoid having two optional arguments that default to an empty list, which can be confusing.

Anyway, I am OK with merging this, your call!

@cigrainger
Copy link
Member Author

Yeah I agree it can be confusing. Perhaps better to document it correctly instead of changing it? Or, could params just be an opt?

@josevalim
Copy link
Member

👍 for improving the docs too!

@cigrainger cigrainger changed the title Default to empty params in DataFrame.from_query Make query params an opt in DataFram.from_query Jan 15, 2024
@cigrainger
Copy link
Member Author

Okay I've made params an opt and defaulted to [].

@josevalim
Copy link
Member

Actually, I am not the biggest fan of this approach, sorry. :( Params are allegedly very common (or should be due for security), so I think it should be more first class than an option. Maybe we can do this:

@doc """
Shortcut for `query/4`.
"""
def query(conn, query, params_or_opts \\ []) when is_list(params_or_opts) do
  if Keyword.keyword?(params_or_opts) do
    query(conn, query, [], params_or_opts)
  else
    query(conn, query, params_or_opts, [])
  end
end

This way we can both as default but without the confusion? 🤔

@cigrainger
Copy link
Member Author

cigrainger commented Jan 15, 2024

Ah, I didn't know they should be encouraged. In that case, I think better to leave it as is but document it -- I'll do that.

@cigrainger cigrainger changed the title Make query params an opt in DataFram.from_query Fix up from_query docs Jan 15, 2024
@cigrainger
Copy link
Member Author

😅 Okay there.

@cigrainger cigrainger merged commit b3e3dd5 into main Jan 15, 2024
3 checks passed
@cigrainger cigrainger deleted the cg/from-query branch January 15, 2024 14:57
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