Merge branch 'dev' into vhs

This commit is contained in:
2025-02-07 19:15:07 +01:00
7 changed files with 323 additions and 105 deletions

51
data/recfiles.md Normal file
View File

@@ -0,0 +1,51 @@
---
title: "Recfiles"
tags: [ "data", "database" ]
---
Create a database of board games:
```bash
database=games.rec
touch $database
entry="Name: Vojvodina"
recins --record "$record" $database
```
Create, read, update, and delete:
```bash
for g in Saboter Carcassonne Chess; do
recins -r "Name: $g" -r "Played: yes" $database
done
query=Carc
recsel --quick=Carc $database
recsel -q $query $database
query=sabat
recsel --case-insensitive -q "$query" --print=Name $database
query=chess
recsel -i -q "$query" -p Name $database
new_field=Played
value=no
recset -f "$new_field" --set-add="$value" $database
recsel $database
value=yes
recset -iq $query -f "$new_field" --set=$value $database
recset -f "$new_field" --delete $database
recsel $database
```
- [Extended example](recfiles/extended.md)
# Resources
- [Recfiles for gemini capsules](gemini://tilde.town/~dozens/gemlog/21.gmi)

118
data/recfiles/extended.md Normal file
View File

@@ -0,0 +1,118 @@
---
title: "Recfiles Extended Example"
tags: [ "data", "database", "recfiles" ]
---
## Create
Make a database for your boardgames, specifying only one field and value:
```bash
database=games.rec
n=Name
g=Vojvodina
touch $database
recins -f $n --value $g $database
recsel $database
```
Insert a few more, with the estimated playtime:
```bash
recins -f Name -v Saboter -f Playtime -v 30 $database
recins -f Name -v Chess -f Playtime -v 30 $database
```
View all games, or select one by number:
```bash
recsel $database
recsel -n 0 $database
```
Each game should note whether or not you have played it yet, so you can add that field and set the default to `yes`.
```bash
f=played
v=yes
recset -f $f -a $v $database
```
...but the field is wrong, it should have a capital letter:
```bash
new_field=Played
recset -f $f --rename $new_field
```
## Read
Check how many records the database has:
```bash
recinf $database
```
Look at just the games you've never played:
```bash
recsel --expression="Played = 'no'" $database
```
Print how many, then just print the names:
```bash
recsel -e "Played = 'no'" --count $database
recsel -e "Played = 'no'" --print=Name $database
```
## Update
To change a game's `Played` field from `no` to `yes`, use `recset` to specify the number, and change that field.
```bash
num=0
f=Played
value=yes
recsel --number=$num $database
recset --number=$num -f $f --set=$value $database
```
Find all games with a playtime of `30`, and set the field `Max_Players` to `4`.
```bash
recset -e "Playtime = 40" -f Max_Players --set 50 games.rec
```
This doesn't work, because that field does not exist.
You can `--set-add` the field, to add it wherever it does not exist.
```bash
recset -e "Playtime = 40" -f Max_Players --set-add 50 games.rec
```
## Delete
Remove `Played` record from first game:
```bash
num=0
recset --number=$num -f Played --delete $database
```
You can comment the line instead of deleting it:
```bash
num=1
recset --number=$num -f Played --delete $database
recsel $database
cat $database
```
Delete an entire record:
```bash
num=2
recdel --number=$num $database
```