Cedalio
Search
K

Database management

After logging in it's time to create a database. In Cedalio, you can create a single database or one database per user.

createDatabase

Creates a Cedalio database. Note that the database might be created but still not ready to use, so in order to start interacting with the database you must check the database status after creating it.
You must be logged in in order to deploy a database
All available databases are shown in the Studio under the Databases tab.

Example

const response = await cedalioSdk.createDatabase();

Returns

Success
Error
{
ok: true,
status: 201,
data: {
deploymentId: 'The deployment id'
}
}
{
ok: false,
status: 401,
error: {
message: 'The server error',
payload: { /* Payload */ }
}
}
It's recommended to save the deploymentId, as you will be needing it for other operations later.

waitForDatabaseDeployment

Waits for the deployment process to finish, either by success or failure. This method polls the deployment's status for a maximum of 60 seconds. The polling stops when the deployment has finished, either via a SUCCESS or FAILED status. If the initial 60 seconds are reached, the polling is stopped and the current status of the database deployment is returned, which can either be SUCCESS, FAILED or PENDING
This method will return a failed response if the API call fails. If the API call succeeds but the database deployment failed, the response will be successful but will return a FAILED status.

Example

const response = await cedalioSdk.waitForDatabaseDeployment({
deploymentId: 'The deployment id'
});

Parameters

  • deploymentId (string): ID of a deployment.

Returns

Success
Error
// Database was successfully deployed
{
ok: true,
status: 201,
data: {
status: 'READY',
databaseContract: 'The Smart contract address for the database'
}
}
// Database deploy failed.
{
ok: true,
status: 200,
data: {
status: 'FAILED',
}
}
// Database deploy is in still in progress.
{
ok: true,
status: 200,
data: {
status: 'PENDING',
}
}
{
ok: false,
status: 401,
error: {
message: 'The server error',
payload: { /* Payload */ }
}
}

Interacting with the database

Once your database is deployed and ready, you will want to interact with its GraphQL API. The endpoint to do so will be:
https://${CEDALIO_PROJECT_ID}.gtw.cedalio.io/deployments/${deploymentId}/graphql
You can also check this url from the Studio for each database in the Databases tab under the URL column
Where CEDALIO_PROJECT_ID is your Cedalio's project id and deploymentId comes from the deploy's response. You can use any GraphQL client to perform requests. An example with Apollo Client:
// tokenId: Your Cedalio JWT token
// deploymentId: The database's deploymentId after you deploy
const createApolloClient = (token: string, deploymentId: string) => {
const httpLink = new HttpLink({
uri: `https://${CEDALIO_PROJECT_ID}.gtw.cedalio.io/deployments/${deploymentId}/graphql`
});
// Add the token in the Authorization header
const authLink = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : ''
}
});
return forward(operation);
});
return new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
});
};