-
Notifications
You must be signed in to change notification settings - Fork 112
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 getting column specification by name #276
Conversation
2dc1cc7
to
59d90e9
Compare
(some extra unrelated commits were initially pushed by mistake, fixed) |
59d90e9
to
039b98b
Compare
examples/get_by_name.rs
Outdated
.query("SELECT pk, ck, value FROM ks.hello", &[]) | ||
.await?; | ||
let (ck_idx, _) = query_result | ||
.get_spec_by_name("ck") |
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.
The get_spec_by_name
function name looks confusing to my 👀. Perhaps something like get_column_spec
is more readable?
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.
Sure. I added _by_name
in case we ever want to get the spec by index, but for that we can just use the vector directly. I'll change to get_column_spec
@@ -75,3 +75,7 @@ path = "clone.rs" | |||
[[example]] | |||
name = "speculative-execution" | |||
path = "speculative-execution.rs" | |||
|
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 can't attach this comment to the commit message, so I'm placing it here)
"It's a first step towards a macro which gets the value by name straight from a result row." - is the commit message correct? If the answer is yes then could you elaborate on the macro idea?
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.
If we also decide to add column specification information to every row (which is a waste, but to consider), then it would be even more convenient to extract values by name. It will have a performance penalty though, so I'm not 100% sure if we want to proceed with that direction
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.
OK, I see. I don't think a macro would be required in that case, we could just add a method (e.g. get_by_name
) or even overload the indexing operator to work on strings for maximum ergonomics (see the std::ops::Index
trait).
I'm not sure about adding column specification per row either. We don't have to clone it for each row, it could keep it behind an atomic pointer (Arc
) so the cost is not as tragic as an e.g. allocation.
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.
Looks good, but we should expose column specification information in the RowIterator
struct, too.
You're right, column spec should probably become part of
|
039b98b
to
94181ee
Compare
v2:
|
This information will be needed to implement getting column values by column name instead of using indexes.
With a column spec and its ordinal number, it will be possible to get specific columns out of the result.
As opposed to getting columns just by their indexes, it's now slightly easier to get a column value by its name. It's a first step towards a macro which gets the value by name straight from a result row.
One of the test cases is slightly amended to also check the mechanism which retrieves column specification from the query result.
94181ee
to
00fabbf
Compare
This series is a first baby step towards solving #271 - which is about enabling users to get column values from result rows by name instead of by index.
Pre-review checklist
Fixes:
annotations to PR description.