-
Notifications
You must be signed in to change notification settings - Fork 28
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
queryValue requires awkward get.get!T #195
Comments
Or alternatively, you can use a different mechanism from |
I suppose this is moot since Phobos' Nullable will eventually require a get call. However, I'll leave this open, because an updated API surely could do better than requiring |
This would also be alleviated somewhat with the move to |
Sounds like an excellent idea. Only potential problem is that some of the Nullable!Variant queryValue(T...)(conn, sql, T args) {...}
int myInt=...;
myConnection.queryRow("SELECT * FROM `myTable` WHERE `a` = ?", myInt) It shouldn’t be a problem to change it to: Nullable!T1 queryValue(T1, T2...)(conn, sql, T2 args) {...} Buuuut….we’d probably want Variant (or rather, TaggedUnion, whatever...) as a default, and I’m wondering if that would be inherently ambiguous: Nullable!T1 queryValue(T1=Variant, T2...)(conn, sql, T2 args) {...} Assuming that works, we’d also need to decide how to handle the case when the type requested doesn’t match the type received. Attempt a silent conversion? Throw? Support both possibilities using different function names:
Yea, |
That is solved with double-layer templates: template queryValue(Ret = Variant)
{
Nullable!Ret queryValue(Args...)(Connection conn, string sql, Args args) { ...}
} Yes, still does full IFTI. At that point, you cannot specify the Args part of the template, but I'm assuming that is not a problem.
Existing behavior is to throw, so just throw. |
In regards to the switch to TaggedUnion, would probably be something like: auto total = conn.queryValue("select count(*) from ...").get.longValue; So really maybe this request will resolve itself once we get there. |
Awesome, sounds great.
Ahh, true. But maybe there's still value (perhaps for generic code?) in being able to specify the requested type as the actual type rather than via TaggedUnion's identifiers? In any case, the template idea is probably just a cleaner interface anyway: It's a little more idiomatic and doesn't require anyone to know anything whatsoever about TaggedUnion. Oh, also, another thought on the whole migration thing: Maybe we could offer a simple util function to just convert the TaggedUnion to a Variant: alias MySQLValue = TaggedUnion!blahblahwhatever...;
Variant toVariant(MySQLValue v) {...}
Nullable!Variant toVariant(Nullable!MySQLValue v) {...}
...
var = conn.queryValue(sql).toVariant; Maybe that could even obviate the need for all those migration path gymnastics I outlined earlier (ugh, might've been in a different ticket...) |
Don't know why I said this, it will still require |
queryValue
returns aNullable!Variant
. Let's say it returns along
(In my case, I was querying aCOUNT(*)
to get the total rows)My code I put was:
But this doesn't work, because
Nullable
intercepts theget
call! So instead I have to do:Which IMO is ugly and annoying. Really this is an issue with
Nullable
andVariant
reusing the same member name, but I doubt that will change.Is it possible to instead specify the type to
queryValue
itself, and have it return aNullable!T
? something like:The text was updated successfully, but these errors were encountered: