Query Projection
Query projections allow you to customize the responses of your queries. You can add projections to any query using the projection
attribute. Here are some examples to give you an overview.
Examples​
You can use the wildcard $
to include or exclude all attributes in a specific query. The default for every query is $: true
, which means to include all attributes.
Another useful feature is retrieving data from connected references.
// let's assume the Person model has the following entry.
// firstname:string
// lastname:string;
// profession: reference to a "Profession Model"
// [ { "key": "P_01", "firstname": "John", "lastname": "Doe", profession: "profession_01" } ]
// $:false in the root projection will result in a response only containing the "key": attribute.
// [ { "key": "P_01" } ]
dcupl.query.one({
model: 'Person',
itemKey: 'P_01',
projection: {
$: false,
},
});
// you can then add specific properties to the result by adding them to the projection
// [ { "key": "P_01", "firstname": "John" } ]
dcupl.query.one({
model: 'Person',
itemKey: 'P_01',
projection: {
$: false,
firstname: true,
},
});
// removing a specific property works just the other way around
// [ { "key": "P_01", "lastname": "Doe", "profession": 'profession_01' } ]
dcupl.query.one({
model: 'Person',
itemKey: 'P_01',
projection: {
$: true,
firstname: false,
},
});
// you can also retrieve data from a connected reference by adding the following
// [ { "key": "P_01", "profession": { "key": "profession_01", "name": "Developer" } } ]
dcupl.query.one({
model: 'Person',
itemKey: 'P_01',
projection: {
$: false,
profession: {
$: true,
},
},
});