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

Allow to specify arguments from the multiple tables for prepared queries #3055

Merged
merged 2 commits into from
Mar 12, 2021

Conversation

arcusfelis
Copy link
Contributor

This PR addresses allows to specify arguments from the multiple table. Which is needed for pubsub queries.

Proposed changes include:

  • Allow to pass table.column as a field name into the prepare call
  • column still works.

@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #3055 (c1e69dd) into master (135fec2) will increase coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3055      +/-   ##
==========================================
+ Coverage   78.53%   78.55%   +0.01%     
==========================================
  Files         378      378              
  Lines       31119    31130      +11     
==========================================
+ Hits        24440    24454      +14     
+ Misses       6679     6676       -3     
Impacted Files Coverage Δ
src/rdbms/mongoose_rdbms_odbc.erl 78.30% <88.88%> (+2.51%) ⬆️
src/elasticsearch/mongoose_elasticsearch.erl 76.92% <0.00%> (-7.70%) ⬇️
src/mongoose_tcp_listener.erl 76.59% <0.00%> (-4.26%) ⬇️
src/mam/mod_mam_elasticsearch_arch.erl 86.60% <0.00%> (-1.79%) ⬇️
src/pubsub/mod_pubsub_db_mnesia.erl 92.40% <0.00%> (-0.43%) ⬇️
src/mod_bosh_socket.erl 78.88% <0.00%> (-0.32%) ⬇️
src/mod_muc_room.erl 77.50% <0.00%> (-0.06%) ⬇️
src/mod_muc_log.erl 77.72% <0.00%> (ø)
src/pubsub/mod_pubsub.erl 71.92% <0.00%> (+0.05%) ⬆️
src/mam/mod_mam_utils.erl 90.03% <0.00%> (+0.33%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 135fec2...c1e69dd. Read the comment docs.

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

Looks good, I have a few minor remarks. I have mixed feelings about the new portmanteau tabcol, but I think it's ok :)

@@ -177,11 +181,11 @@ field_name_to_mapper(_ServerType, TableDesc, FieldName) ->
fun(P) -> {ODBCType, [P]} end
end.

field_to_odbc_type(FieldName, TableDesc) ->
case lists:keyfind(FieldName, 1, TableDesc) of
field_to_odbc_type(TabCol = {Table, Column}, TableDesc) ->
Copy link
Member

Choose a reason for hiding this comment

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

This should be named 'tabcol_to_odbc_type' for consistency.

@@ -76,18 +78,20 @@ query(Connection, Query, Timeout) ->
Fields :: [binary()], Statement :: iodata()) ->
{ok, {binary(), [fun((term()) -> tuple())]}}.
prepare(Connection, Name, Table, Fields, Statement) ->
try prepare2(Connection, Table, Fields, Statement)
TabCols = fields_to_tabcol(Fields, Table),
Copy link
Member

@chrzaszcz chrzaszcz Mar 11, 2021

Choose a reason for hiding this comment

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

Just to make sure: the only reason we don't just accept TabCols as an argument instead of Fields is that you consider the 'tab.col' syntax better than {tab, col}, right? I am aware that we would need to accept both a single atom or a tuple as the argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the main reason is that it's the same syntax as in SQL queries, so less confusion, easier to write such queries.
We don't do "SELECT {tab, col}", so I am not reinventing the wheel :)

So, for me it just looks more natural, even if we have to split it in the backed module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, it's the same reason why Fields are atoms, even if we convert them to binaries in the prepare call.
It just looks a bit cleaner.

@arcusfelis
Copy link
Contributor Author

tabcol is just because "fully specified column name" is too long.

@chrzaszcz chrzaszcz merged commit bf34516 into master Mar 12, 2021
@chrzaszcz chrzaszcz deleted the mu-rdbms-multi-table-prep-queries branch March 12, 2021 11:54
@leszke leszke added this to the 4.2.0 milestone Apr 16, 2021
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.

None yet

3 participants