Elemental lowcode development platform.
The storage service allows you to access data types defined within the storage system. It provides the following methods:
Each of these methods is covered in more detail below.
Parameters:
name
- string, the name of the collection to detailtoken
- string, the access token to use to access the API optionalReturns the JSON response from the relevant .details endpoint on the storage service. More details on this response payload can be found within the storage system documentation.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly.
This can be called from within a controller like so:
module.exports = {
events : {
load : (event) => {
return this.storageService.detailCollection(
"books"
).then((result) => {
}).catch((err) => {
});
}
}
};
Parameters:
path
- string, the root path of the collection to fetch fromstart
- integer, the index of the first item to retrievecount
- integer, the maximum number of items to retrievefilters
- object, the filters to apply when fetching itemstoken
- string, the access token to use to access the API optionalReturns a paginated list of entities from the named collection. More details on this response payload can be found within the storage system documentation.
Filters can be applied to the entities to only include items that have certain values. Filters are based upon the JSON path of the value within the entity and match (equality) against a single value.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly.
This can be called from within a controller like so:
module.exports = {
events : {
myEvent : (event) => {
return this.storageService.getList(
`authors/${event.authorId}/books`,
1,
10,
{
"$.rating" : "10"
}
).then((result) => {
}).catch((err) => {
});
}
}
};
Parameters:
path
- string, the root path of the collection to fetch fromid
- guid (string), the id of the entity to retrievetoken
- string, the access token to use to access the API optionalReturns a single entity from the named collection. More details on this response payload can be found within the storage system documentation.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly.
This can be called from within a controller like so:
module.exports = {
events : {
myEvent : (event) => {
return this.storageService.getEntity(
`authors/${event.authorId}/books`,
"16aeb990-4f40-4060-892c-bebe9456de3f"
).then((result) => {
}).catch((err) => {
});
}
}
};
Parameters:
path
- string, the root path of the collection to create the entity inentity
- object, an object that matches the definition of entities within the named collection, the contents of which will be used to create the new entitytoken
- string, the access token to use to access the API optionalCreates a new entity within the named collection. More details on this response payload can be found within the storage system documentation.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly. This promise will return the newly created object as the result.
This can be called from within a controller like so:
module.exports = {
events : {
myEvent : (event) => {
return this.storageService.createEntity(
`authors/${event.authorId}/books`,
{
hello : "world"
}
).then((result) => {
}).catch((err) => {
});
}
}
};
Parameters:
path
- string, the root path of the collection to update an entity inid
- guid, the id of the entity to updateentity
- object, an object that matches the definition of entities within the named collection, the contents of which will replace the entity with the given idtoken
- string, the access token to use to access the API optionalUpdates an entity within the collection. More details on this response payload can be found within the storage system documentation.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly.
This can be called from within a controller like so:
module.exports = {
events : {
myEvent : (event) => {
return this.storageService.updateEntity(
`authors/${event.authorId}/books`,
"16aeb990-4f40-4060-892c-bebe9456de3f",
{
hello : "world"
}
).then((result) => {
}).catch((err) => {
});
}
}
};
Parameters:
path
- string, the root path of the collection to update an entity inid
- guid, the id of the entity to updateentity
- object, an object that matches the definition of entities within the named collection, the contents of which will replace the entity with the given idtoken
- string, the access token to use to access the API optionalPartially updates an entity within the collection. More details on this response payload can be found within the storage system documentation.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly.
This can be called from within a controller like so:
module.exports = {
events : {
myEvent : (event) => {
return this.storageService.updateEntity(
`authors/${event.authorId}/books`,
"16aeb990-4f40-4060-892c-bebe9456de3f",
{
hello : "world"
}
).then((result) => {
}).catch((err) => {
});
}
}
};
Parameters:
path
- string, the root path of the collection to delete fromid
- guid (string), the id of the entity to deletetoken
- string, the access token to use to access the API optionalDeletes an entity from the named collection. More details on this response payload can be found within the storage system documentation.
This method returns a Promise which can resolve or reject. You must make sure to handle rejections correctly.
This can be called from within a controller like so:
module.exports = {
events : {
myEvent : (event) => {
return this.storageService.deleteEntity(
`authors/${event.authorId}/books`,
"16aeb990-4f40-4060-892c-bebe9456de3f"
).then((result) => {
}).catch((err) => {
});
}
}
};