Create your composite
The second step in getting started with ComposeDB on Ceramic is creating your composite to serve as your database schema. In this guide, we will create your first composite.
Before continuing, you must have set up your environment in the previous step
Overview
A composite is your database schema for ComposeDB, which includes a collection of data models. Once created, your composite instructs your node which models to index and also allows your client to perform queries and mutations on these models.
Data Model Catalog
The Model Catalog contains all models created by other ComposeDB developers. By creating or reusing models within the model catalog in your composite, you can instantly share and sync data with other applications. This brings native app data composability to Web3 -- no more API integrations.
To list all models in the model catalog, run the following command:
composedb model:list --table
Here, the flag --table
will display the output in an organized table view and provide more details about each model’s functionality. By default, this command lists models in production on mainnet. To see models being developed on clay testnet, specify --network=testnet-clay
:
composedb model:list --network=testnet-clay --table
Response: Below see a small snippet of the the output table. Each model has the following properties:
Name
- model nameUnique ID
- unique identifier (stream ID) for the modelDescription
- description of the model’s functionality
Creation
In this section we will demonstrate how to create a composite by downloading models from the model catalog.
Single model
You can fetch any existing model from the catalog by referencing the model’s unique ID. For example, for your basic social media app, use the existing model SimpleProfile
. To fetch the model, to your working directory, take note of the model stream ID in the table above and run the following command:
composedb composite:from-model kjzl6hvfrbw6c5ajfmes842lu09vjxu5956e3xq0xk12gp2jcf9s90cagt2god9 --ceramic-url=http://localhost:7007 --output=my-first-composite-single.json
After running the command above, your will have the SimpleProfile
model stored locally in a file called my-first-composite-single.json
.
Multiple models
If your application needs multiple models, for example the SimpleProfile
and Post
models, you can. To fetch them, take note of the model stream IDs and provide them in a ComposeDB CLI command as follows:
composedb composite:from-model kjzl6hvfrbw6c5ajfmes842lu09vjxu5956e3xq0xk12gp2jcf9s90cagt2god9 kjzl6hvfrbw6c99mdfpjx1z3fue7sesgua6gsl1vu97229lq56344zu9bawnf96 --ceramic-url=http://localhost:7007 --output=my-first-composite.json
The output of this command will be a composite file named my-first-composite.json
.
Usage
Deployment
You will have to deploy the composite with fetched models to your local Ceramic node so that they can be used when building and running your applications. This can be achieved by using ComposeDB CLI and referencing the composite file of fetched models in your local environment as shown below. Note that you have to provide your did private key to deploy the model:
composedb composite:deploy my-first-composite.json --ceramic-url=http://localhost:7007 --did-private-key=your_private_key
Whenever composites are deployed, the models will be automatically indexed. This also means that these models are shared across the network (at the moment, only Clay testnet). If you check the output produced by the terminal that runs your Ceramic local node, you should see a similar output:
IMPORTANT: Starting indexing for Model kjzl6hvfrbw6c5ajfmes842lu09vjxu5956e3xq0xk12gp2jcf9s90cagt2god9
IMPORTANT: Starting indexing for Model kjzl6hvfrbw6c99mdfpjx1z3fue7sesgua6gsl1vu97229lq56344zu9bawnf96
IMPORTANT: Creating Compose DB Indexing table for model: kjzl6hvfrbw6c5ajfmes842lu09vjxu5956e3xq0xk12gp2jcf9s90cagt2god9
IMPORTANT: Creating Compose DB Indexing table for model: kjzl6hvfrbw6c99mdfpjx1z3fue7sesgua6gsl1vu97229lq56344zu9bawnf96
This means that the composite was deployed and the models were indexed on your local node successfully! 🎉
Compilation
The last step left is compiling the composite. This is necessary to interact with the data in the next step of this guide:
composedb composite:compile my-first-composite.json runtime-composite.json
The output of this command will be a json file called runtime-composite.json
Next Steps
Now that you have created your composite, you are ready to use it: Interact with data →