Closed AstraLuma closed 6 years ago
Can you show me an example of the YAML you expect?
my_mapping:
50: spam
60: eggs
This sort of data structure is not currently expressible in the YORM schema, where I don't know the number of rows in advance, but I do know the shape of the rows.
(Ok, I could have a list of yet-another-class, but that seems needless tedious for a simple key-value mapping.)
Yeah, currently YORM expects something like:
my_mapping:
- key: 50
value: spam
- key: 60
value: spam
so that it can enforce a schema on each nested object. What does your class look like before adding the YORM decorators? Certainly you don't have attributes that are integers.
This is a YORM-native schema.
The use case is that in a GitLab tool, I have (attached to a data object) a list of merge request IDs, and a note (comment) ID within that MR. The Pythonic way to do this would to have a dict mapping MR IDs to Note IDs.
You could always try using yorm.types.Object
as the attribute type which should handle arbitrary dictionary-like objects (but without schema validation).
Or try extending one of the existing types (see yorm.types.extended
for examples).
I have found that explicitly defining keys for values (i.e. name: value
) is better off in the long run and easier to reason about the data outside of YORM.
Object
doesn't invoke autosave, does it?
The auto_save
option only applies to the root object -- the one sync()
is applied to.
Did you have any luck with this approach?
Yeah, it's working and I haven't touched the code in months.
Glad to hear.
Is there a variation on Dictionary that implements mappings?
That is to say, it doesn't have a fixed list of keys, but all keys are Integers and all values are Strings.