Using metadata
- Python
- JavaScript
Key/value metadata can be written to entities using the metadata property and also used to query entities.
The metadata property has a similar interface as a dictionary and keys can be printed using the keys method:
print(new_sequence['metadata'].keys())
['frame_padding', 'focal_length']
or items:
print(new_sequence['metadata'].items())
[('frame_padding': '4'), ('focal_length': '70')]
Read existing metadata:
print(new_sequence['metadata']['frame_padding'])
'4'
Setting metadata can be done in a few ways where that later one will replace any existing metadata:
new_sequence['metadata']['frame_padding'] = '5'
new_sequence['metadata'] = {
'frame_padding': '4'
}
Entities can also be queried using metadata:
session.query(
'Sequence where metadata any (key is "frame_padding" and value is "4")'
)
Querying
Metadata can be queried as a part of an entity.
const metadata = (await Session.query('select metadata from TypedContext where name is "Compositing" limit 5')).data[0].metadata;
Entities can also be queried using metadata.
const tasksWithFramePaddingFour = (await Session.query('select name from Task where metadata any (key is "frame_padding" and value is "4")')).data;
Creating, updating and deleting
Creating and updating metadata with the JavaScript API is done most easily using Session.ensure()
on the Metadata entity type. This will create the metadata if it doesn't exist, and update the metadata value if it does exist.
Session.ensure(
"Metadata",
{
key: "foo", // The metadata key
value: "bar", // The metadata value
parent_id: "e8925613-d74c-4faf-a654-99352ffb2632", // The entity that should contain the metadata
parent_type: "Task", // The type of the entity
},
["key", "parent_id"] // The primary key is a composite of the key and parent_id
);
To delete the metadata Session.delete()
would be used with the ID of the entity containing the metadata and the metadata key
. The order of the primary keys is important, with the entity id (called parent_id in the schema) being the first one.
Session.delete(
"Metadata", ["e8925613-d74c-4faf-a654-99352ffb2632", "foo"]
);