Skip to main content

Create Module Database

To deliver a high level availability to all the resources we have decided to keep all the PluginsData to a centeral database and maintain it reguarly, this means the developers shouldn't worry about database deployments and configurations.

The following guide shows how to create/update the database structure and how to connect to it from your backend application.

Step 1: Setup Database Structure

Once you are in the Developers Portal, click on one of the plugins and scroll all the way down. You should be able to see the interactive Database Structure section with a an empty input asking for a new_table. Once you write a table_name and click create you should now be able to add columns to that table.

Let's go ahead and create this structure for our School Plugin.

table_name: teachers
columns:
* fullname: string
* age: int
* exp: int
* description: string

---

table_name: students
columns:
* fullname: string
* parent_name: string
* parent_relation: string
* age: int
* grade: int

Note: The two columns ['id', 'business_id'] are added automatically!

Note: The reset button will reset the structure to the last saved point, which means if you click Save and Reset it doesn't reset that structure again. So be very careful and double-check the structure before clicking save. Of course you are always able to edit the structure, but if you delete tables/columns you may lose the live data

Step 2: Access Database

We are fully flexible in terms of the Backend Technologies and therefor each plugin can be created in your language/tech-stack of your choice. ( we will talk more about this in the Backend-Deployment-Section of this doc )

We are using an API gateway to access the database and the following is the query structure for it.

Endpoint: https://lajward-mis.dev:3002/db/query
Authorization: Bearer {jwt_token}

Body Example 1:
{
"query": {
"type": "select",
"table": "school___teachers",
"cols": ["fullname", "age"],
"filters": [],
"limit": 0,
"offset": 0,
"order_by": []
}
}


Body Example 2:
{
"query": {
"type": "create",
"table": "school___teachers",
"cols": ["fullname", "age"],
"rows": [["Khalid H.", 12], ["Rashid H.", 21]]
}
}

Body Example 3:
{
"query": {
"type": "create",
"table": "school___students",
"cols": ["grade"],
"vals": [8],
"filters": [
{
"col": "age",
"op": ">",
"value": 18
}
]
}
}

Note: in the central database the table_names are concatinated in the following way {plugin-name}___{table-name}

Note: The jwt_token is passed by the frontend user ( school frontend plugin ) to the backend ( school backend plugin ) and you shall pass that to the base ( this endpoint ) to get the proper related data to that user via this plugin.

Feel free to playaround with this and please note that the endpoint is developer friendly and is providing helpful errors when something goes wrong