Add practice exercise: space-age - #107
Conversation
|
@exercism/sqlite Thoughts on "easy" with a JSON object? Or, thoughts on using a JSON object vs a simple(r) output? |
| @@ -0,0 +1,29 @@ | |||
| DROP TABLE IF EXISTS tmp; | |||
| CREATE TEMPORARY TABLE tmp ( | |||
| p TEXT UNIQUE NOT NULL, | |||
There was a problem hiding this comment.
Could we use more descriptive names?
| UPDATE "space-age" | ||
| SET result = JSON_OBJECT('error', 'not a planet') | ||
| WHERE NOT EXISTS (SELECT 1 FROM tmp WHERE p = planet) | ||
| ; | ||
|
|
||
| UPDATE "space-age" | ||
| SET result = JSON_OBJECT( | ||
| 'age', | ||
| ROUND("space-age".seconds / 31557600.0 / tmp.op, 2) | ||
| ) | ||
| FROM tmp | ||
| WHERE "space-age".planet = tmp.p | ||
| AND "space-age".result ISNULL | ||
| ; |
There was a problem hiding this comment.
This indentation style isn't consistent with much of the other files.
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
🤔 It's better just use a "common" result datatype to store both real and text (just the error description)? I can change this if you like and remove json at all. |
I don't think one is objectively better than the other. Hence me soliciting thoughts from the other maintainers. A JSON object is richer and more nuanced; it avoids a column that might hold a string or a number. It's "better" from the technical perspective of being more detailed. But it's more complicated. For an easy exercise, there's value in keeping things easy. Adding JSON over a plain value makes it "more" complicated. But with the example in the instructions.append, it might be only very slightly more complicated and still be easy. Or not. |
|
A third option that was suggested by @BNAndras is to simply omit those error tests. Those don't add a ton of value and simplify things a fair bit. That would be in line with what we did in the grains and collatz exercises. I think that might be a very good option here. |
So there's already a "pattern" I can follow. Great! I'll do that! 😁 |
|
I agree that the error test can be omitted. An alternate implementation is to add an |
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
instructions.append.md.