Nested query for YAML based TinyDB table #554
-
I am struggling with performing nested queries on my YAML based TinyDB table, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I guess you're using the YAMLStorage from https://tinydb.readthedocs.io/en/latest/extend.html? In general, TinyDB is not particularly strong when searching a weight_training_log:
'188':
date: '2024-01-07'
start_time: '15:50'
end_time: '16:22'
timezone: CET
split: push
exercises:
- type: incline_db_press
sets:
- set_number: 1
reps: 8
weight: 40 kg
- set_number: 2
reps: 10
weight: 40 kg
- set_number: 3
reps: 8
weight: 40 kg
- type: db_incline_flys
sets:
- set_number: 1
reps: 10
weight: 28 kg
- set_number: 2
reps: 10
weight: 28 kg
- set_number: 3
reps: 8
weight: 28 kg
- type: seated_db_shoulder_press
sets:
- set_number: 1
reps: 10
weight: 24 kg
- set_number: 2
reps: 10
weight: 24 kg
- set_number: 3
reps: 10
weight: 24 kg
- type: behind_the_back_cable_lateral_raise
sets:
- set_number: 1
reps: 12
weight: 4.5 kg
- set_number: 2
reps: 12
weight: 4.5 kg
- set_number: 3
reps: 12
weight: 4.5 kg
- type: seated_db_rear_lateral_raise
sets:
- set_number: 1
reps: 12
weight: 10 kg
- set_number: 2
reps: 12
weight: 10 kg
- set_number: 3
reps: 12
weight: 10 kg
- type: static_hang
sets:
- set_number: 1
reps: 1
weight: BODYWEIGHT kg
duration: 60 seconds
# ... db = TinyDB('test.yml', storage=YAMLStorage)
print(db.table('weight_training_log').search(where('exercises').any(where('sets').any(where('weight').search('BODYWEIGHT'))))) |
Beta Was this translation helpful? Give feedback.
I guess you're using the YAMLStorage from https://tinydb.readthedocs.io/en/latest/extend.html?
In general, TinyDB is not particularly strong when searching a
dict
for an entry with a particular value.Query.any
for example will run on adict
's keys, not values. If you store your exercises as a list, you can easily find an entry withweight
containingBODYWEIGHT
: