Skip to content

Filtering Data by Deployment Information

During the development process, you may create many different Private Dapp Realms. However, all the app data will be put into the same Cirrus table. So when you need to retrieve multiple/all entries of a given asset table, you will get the asset data from all of these different deployments without any additional filters on your search. This of course will result in unwanted data from invalid, older deployments showing up in your queries. To resolve this, there must be a way to filter data across these deployments in an easy way, without having to constantly change the contract names (causing the data to be inserted into a different Cirrus table for each deployment.)

The solution to this problem is to include a state variable in every asset contract that contains the unique ID of the Private Dapp Realm created at deployment time that this asset is a part of. Whenever an asset is created, we can programmatically set this value to the “parent” shard ID from our application's server.

Example:

contract Asset {

    string public dappShardId;

    constructor(string _dappShardId) {
        dappShardId = _dappShardId;
    } 
}

Finally, when querying data from our application middleware, we must filter the rows by the value of the dappShardId column, where all results must be equal to the ID of the current Private Dapp Realm:

GET /cirrus/search/<Org>-Asset?dappShardId=eq.<dappShardId>