Create your composite
Create your composite to serve as your graph 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.
List all models
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
Notice each model has the following properties:
Name
- model nameUnique ID
- unique identifier (stream ID) for the modelDescription
- description of the model’s functionality
Creating the composite
In this section we will show how to create a composite by downloading models from the model catalog.
Using a 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 kjzl6hvfrbw6c5i55ks5m4hhyuh0jylw4g7x0asndu97i7luts4dfzvm35oev65 --ceramic-url=http://localhost:7007 --output=my-first-composite.json
You should see the following output in your terminal:
✔ Creating a composite from models... Composite was created and its encoded representation was saved in my-first-composite.json
This output means that you now have the SimpleProfile
model stored locally in a file called my-first-composite.json
.
Using 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 kjzl6hvfrbw6c5i55ks5m4hhyuh0jylw4g7x0asndu97i7luts4dfzvm35oev65 kjzl6hvfrbw6c822s0cj1ug59spj648ml8a6mbqaz91wx8zx3mlwi76tfh3u1dy --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
.
Using the composite
Deploying the composite
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
You should see the output similar to the one below:
ℹ Using DID did:key:z6MkoDgemAx51v8w692aZRLPdwP6UPKj3EgUhBTvbL7hCwLu
✔ Deploying the composite... Done!
["kjzl6hvfrbw6c5i55ks5m4hhyuh0jylw4g7x0asndu97i7luts4dfzvm35oev65"]
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 kjzl6hvfrbw6c5i55ks5m4hhyuh0jylw4g7x0asndu97i7luts4dfzvm35oev65
IMPORTANT: Starting indexing for Model kjzl6hvfrbw6c822s0cj1ug59spj648ml8a6mbqaz91wx8zx3mlwi76tfh3u1dy
IMPORTANT: Creating ComposeDB Indexing table for model: kjzl6hvfrbw6c5i55ks5m4hhyuh0jylw4g7x0asndu97i7luts4dfzvm35oev65
IMPORTANT: Creating ComposeDB Indexing table for model: kjzl6hvfrbw6c822s0cj1ug59spj648ml8a6mbqaz91wx8zx3mlwi76tfh3u1dy
This means that the composite was deployed and the models were indexed on your local node successfully! 🎉
Compiling the composite
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
You should see the following output in your terminal:
✔ Compiling the composite... Done!
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 →