Imagine you need to perform a server-side data validation on every put request for a given table. If the validation logic succeeds the sent data would be persisted into the Realtime Cloud Storage table, otherwise an exception would be returned to the requesting client and data would not be saved.
Until now you would need to manage your own server to host this server-side validation. With the new Code Hosting feature you can use our enterprise-grade cloud infrastructure and host your code with us. We will manage all aspects regarding security, availability and scalability.
For this server-side validation use case you would use a table trigger, a procedural code that is automatically executed in response to certain events (in this case the item put) on a particular table in the Cloud Storage database.
There are five main trigger operations:
Each trigger operation is divided in two events, before and after.
before trigger is executed before the data operation is committed to the database and the
after trigger is executed after the data operation was committed successfully to the database.
For the use case above you would use the
beforePut trigger to allow the new item put to be canceled if it’s not valid. It couldn’t be simpler.
To add triggers to your Realtime Cloud Storage tables you just select the appropriate trigger function to the desired trigger name (we’ll explain functions in the next sections). The following image shows the trigger list for a given Realtime Cloud Storage table (the red rectangle shows that function
validateDelete will be executed before each item is deleted from this database table):
In the next section we'll talk about custom functions, a powerful way of exposing your business logic as a RESTful API.