gamelog/doc/learnings.md

46 lines
2.1 KiB
Markdown

### Intro
I think the main benefit to recutils is having a human readable, plain-text database that you can edit.
Querying and inserting is okay.
I don't have a use case for using Joins on records, but the fact that you can means that recutils is pretty robust
I think that recutils could be a really good format for easily tracking data in version control. It is a good "source" database that can then be exported to csv and SQL. `csvkit`, e.g., can output straight to sqlite
### Sorting
Fri, 11 Feb 2022 14:26:47 -0700
Okay check this out.
You can sort your fields at query time by passing the `--sort Key` option to recsel. And you can set a `%sort Key` default in the recfile itself. *But sorting can only ever be ascending*. Says so right in the docs.
> The sorting is always done in ascending order...
>
> <https://www.gnu.org/software/recutils/manual/Sorted-Output.html#Sorted-Output>
I want a blog-style list of records with the most recently updated at the top, so I need my records in descending order. I settled on this craptastic workaround of querying my records sorted by `Updated`, convert to CSV, convert to JSON, `jq 'reverse'`, convert back to CSV, and convert back to recfiles. (I only bother going all the way back to recfiles because I already wrote the recfile template I want to use to generate markdown.)
Here are the relevant snippets from my justfile:
```
# featuring descending sort!
markdown:
recsel -S Updated {{database}} | rec2csv | csvjson | jq 'reverse | map(.Notes |= gsub("\n"; "\n\n"))' | in2csv -f json | csv2rec | recfmt -f templates/markdown.template
# html out
html:
just markdown | pandoc -t html --toc -s --metadata title="Games!" -B templates/before.html -A templates/after.html -o dist/games.html
```
This seems like a huge oversight of `recsel`. I can't imagine I'm the only person who wants control over the order of their sort!
### Templates
> You can use any selection expression in the slots, including conditionals and string concatenation.
>
> -<https://www.gnu.org/software/recutils/manual/Templates.html#Templates>
...no you can't