-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
what is the sqlite_orm equivalent to ifnull(X,Y) ? #715
Comments
I found coalesce is the substitution for ifnull. But I am at a loss as to how to write this SQL in sqlite_orm... could you give me a hand here? I have the following code: struct response_1_count : alias_tag {
static const std::string& get() {
static const std::string res = "response_1_count";
return res;
}
};
struct i : alias_tag {
static const std::string& get() {
static const std::string res = "i";
return res;
}
}; and this: auto lines = storage.select(columns(alias_column<als_c>(&Claim::id), as<response_1_count>(coalesce<int>(alias_column<als_c>(&Claim::other_system_id),0))),
as<i>(left_join<als_i>(on(c(alias_column<als_i>(&Invoice::)))
); ///?????? where: using als_c = alias_c<Claim>;
using als_p = alias_p<Patient>;
using als_d = alias_d<Doctor>;
using als_s = alias_s<Specialty>;
using als_m = alias_m<Medication>;
using als_i = alias_i<Invoice>;
using als_j = alias_j<INSResponse>;
using als_k = alias_k<INSResponseLine>;
using als_l = alias_l<Claim>;
using als_q = alias_q<Invoice>; |
I have this going in the right direction but still need to insert the nested select: auto lines = storage.select(columns(alias_column<als_c>(&Claim::id), as<response_1_count>(coalesce<int>(alias_column<als_c>(&Claim::other_system_id), 0))),
left_join<als_i>(on(c(alias_column<als_i>(&Invoice::fkey_claim)) == alias_column<als_c>(&Claim::id)))); This produces the following SQL: SELECT 'c'."id_claim", COALESCE('c'."other_system_id", ?) AS response_1_count
FROM 'Claims' c
LEFT JOIN 'Invoices' 'i' ON ('i'."fkey_claim" = 'c'."id_claim") ?? |
Oh man LEFT JOIN
(
SELECT fkey_claim, COUNT(*) AS response_1_count
FROM Invoices
WHERE fkey_INSResponse = 1
GROUP BY fkey_claim
) is not supported right now. Actually I even did not know about this feature in SQLite. I can add it soon. Let's leave this issue opened until it is implemented. It may look like:
|
@juandent |
Thanks!!! In what branch? master? |
dev |
is this still current: "LEFT JOIN |
yes it is. I am thinking about proper API |
good!! 👍 |
I have this select: Can it be written in sqlite_orm? In particular how can we deal with ifnull function?
The text was updated successfully, but these errors were encountered: