Queries
Queries are defined in .pquery.js
files.
These files can be used to perform model transformation - that is to convert a part of your model into some new data collection.
Queries are run separately from code generation. Everytime you run the queries, they will create .pdata.json
files in the .projor/_generated
directory. These files will be picked up by ProJor during the code generation phase.
This means, that if you change data in a data collection, and you have a query that depends on this data, you need you run the queries to update the generated data collections.
An example query file looks like this:
javascript
/// Queries receive the `project` variable, which contains the whole project model.
const entitiesDataCollection = project.data.find(d => d.id === 'entities');
function createEntityOperations(entity) {
return [
{
name: 'create_' + entity.name,
description: 'Creates a new ' + entity.name + ' in the system',
/// The ID of the entity is `data-collection-id#object-name`
entity: `entities#${entity.name}`
},
{
name: 'delete_' + entity.name,
description: 'Deletes a ' + entity.name + ' from the system',
entity: `entities#${entity.name}`
},
{
name: 'update_' + entity.name,
description: 'Updates a ' + entity.name + ' in the system',
entity: `entities#${entity.name}`
}
];
}
return {
id: 'entity-operations',
name: 'Entity Operations',
description: 'Operations for entities',
schema: 'EntityOperation',
/// Convert each entity object into a list of operations
objects: entitiesDataCollection.objects.flatMap(createEntityOperations)
}