Writing Your Own External Data Connectors
Learn how to write your own external data connectors for budibase.

What are External Data Connectors?

External data connectors are modules that allow you to connect your budibase application to a whole host of database and API technologies. You can connect your budibase apps to relational databases, HTTP APIs and more. You can find a list of all the currently supported budibase data connectors here.

Data Connector Structure

To see real world examples of data connectors in budibase, have a look through the existing ones here.

Data connectors are made up of datasources and queries.
A datasource usually points to a single database instance or API.
Queries are the different data fetching operations against a datasource.
For example, your local postgres instance would be a datasource, and you can create a whole host of different queries against that postgres instance. You can bind budibase UI components to queries - such as grids, tables, repeaters and more.
When writing a data connector, you need to define two things in your code:
    Schema - This defines the options for the data connector.
    Integration Code - A JavaScript class containing the actual code that will be executed by budibase when executing operations against the datasource. The integration class must contain create, read, update and delete methods.

Tutorial: Creating a MySQL Data Connector

Let's walk through an example. We are going to create a budibase data connector for MySQL, the popular RDBMS.

Steps

    Create schema and integration code
    Add an icon for the integration
    Test our integration

Setup

If you already have MySQL setup, feel free to skip this section and use your own existing MySQL database for this tutorial.
If you haven't installed MySQL, you will need to install it (docs here). Alternatively, you can run MySQL inside docker, which is the approach we are going to take. Install docker, and run the following command to run MySQL on your machine.
1
docker run --name budi-mysql -p3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
Copied!

(Optional) Seed your database

You may want to set up a test database and some tables for testing your integration.
Open up the MySQL command line client, or use your favourite MySQL GUI client to connect to your MySQL database. If you are using docker, you can run the MySQL command line client inside docker by running the following command:
1
docker exec -it budi-mysql mysql -p my-secret-pw
Copied!
Create a database
Once connected, run the following commands to set up your database.
1
create database budibase;
2
use budibase;
Copied!
Create a Test Table
1
create table people (
2
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
3
firstname VARCHAR(30),
4
email VARCHAR(50),
5
age INT
6
);
Copied!

Create data

1
INSERT INTO `people` (firstname, email, age) VALUES ('test', '[email protected]', 25);
Copied!
Ok, we are now ready to write our data connector!

Finding a Library

To implement our data connector, we need a library that will allow the budibase server (Built on NodeJS) to connect to our database. The simplest choice here would be to just use the official MySQL node connector, a hugely popular and mature library.
GitHub - mysqljs/mysql: A pure node.js JavaScript Client implementing the MySQL protocol.
GitHub
Let's install this libary in the server directory.
1
cd packages/server
2
yarn add mysql
Copied!
We have now installed MySQL and we are ready to write our integration. Create a new file in packages/server/src/integrations/mysql.js with the following contents:
1
const mysql = require("mysql")
2
​
3
const SCHEMA = {
4
// Optional link to docs, which gets shown in the UI.
5
docs: "https://github.com/mysqljs/mysql",
6
datasource: {},
7
query: {},
8
}
9
​
10
class MySQLIntegration {}
11
​
12
module.exports = {
13
schema: SCHEMA,
14
integration: MySQLIntegration,
15
}
16
​
Copied!
Now it's time to start setting up our schema. You will notice that we've created the main building blocks of a budibase data connector (schema, integration class), and exported them. This means we can now just focus on our implementation by filling them out. Let's start by creating our datasource configuration. When you look at the docs for the node MySQL connector, we are told how to configure the client, which looks a little like this:
1
const connection = mysql.createConnection({
2
host : 'localhost',
3
user : 'me',
4
password : 'secret',
5
database : 'my_db'
6
});
7
​
Copied!
In order to allow users to add these values through the budibase builder, we will need to update our code to look like below. Notice how we have created schema values to match the ones the MySQL client expects. The user fills these values in from the builder and they get passed to our integration.
1
const mysql = require("mysql")
2
​
3
const SCHEMA = {
4
docs: "https://github.com/mysqljs/mysql",
5
datasource: {
6
host: {
7
type: "string",
8
default: "localhost",
9
required: true,
10
},
11
user: {
12
type: "string",
13
default: "root",
14
required: true,
15
},
16
password: {
17
type: "password",
18
default: "root",
19
required: true,
20
},
21
database: {
22
type: "string",
23
required: true,
24
},
25
},
26
query: {},
27
}
28
​
29
class MySQLIntegration {
30
constructor(config) {
31
/**
32
* This is the config passed in from the schema. It should look something like this, with your own values:
33
* {
34
* host: "localhost",
35
* user: "myuser",
36
* password: "somepassword",
37
* database: "mydatabase"
38
* }
39
* */
40
this.config = config
41
this.client = mysql.createConnection(config)
42
}
43
}
44
​
45
module.exports = {
46
schema: SCHEMA,
47
integration: MySQLIntegration,
48
}
49
​
Copied!
Following our schema configuration, the next part is to create a query. We are going to create a simple query to allow us to read data from our MySQL instance. As mentioned in the Data Connector Structure section, integration methods must be one of the following:
    create()
    read()
    update()
    delete()
Let's write the code for our read() method.
1
const mysql = require("mysql")
2
​
3
const SCHEMA = {
4
docs: "https://github.com/mysqljs/mysql",
5
datasource: {
6
host: {
7
type: "string",
8
default: "localhost",
9
required: true,
10
},
11
user: {
12
type: "string",
13
default: "root",
14
required: true,
15
},
16
password: {
17
type: "password",
18
default: "root",
19
required: true,
20
},
21
database: {
22
type: "string",
23
required: true,
24
},
25
},
26
query: {
27
// The read query takes SQL as a parameter
28
read: {
29
type: "sql",
30
},
31
},
32
}
33
​
34
class MySQLIntegration {
35
constructor(config) {
36
/**
37
* This is the config passed in from the schema. It should look something like this, with your own values:
38
* {
39
* host: "localhost",
40
* user: "myuser",
41
* password: "somepassword",
42
* database: "mydatabase"
43
* }
44
* */
45
this.config = config
46
this.client = mysql.createConnection(config)
47
}
48
​
49
read(query) {
50
// Node MySQL is callback based, so we must wrap our call in a promise
51
return new Promise((resolve, reject) => {
52
this.client.connect()
53
return this.client.query(query.sql, (error, results) => {
54
if (error) return reject(error)
55
resolve(results)
56
this.client.end()
57
})
58
})
59
}
60
}
61
​
62
module.exports = {
63
schema: SCHEMA,
64
integration: MySQLIntegration,
65
}
66
​
Copied!
Next we need to add our integration to packages/server/src/integrations/index.js. This exports our integration and makes it available to the builder.
1
const postgres = require("./postgres")
2
const dynamodb = require("./dynamodb")
3
const mongodb = require("./mongodb")
4
const elasticsearch = require("./elasticsearch")
5
const couchdb = require("./couchdb")
6
const sqlServer = require("./microsoftSqlServer")
7
const s3 = require("./s3")
8
const airtable = require("./airtable")
9
const mysql = require("./mySql")
10
​
11
const DEFINITIONS = {
12
POSTGRES: postgres.schema,
13
DYNAMODB: dynamodb.schema,
14
MONGODB: mongodb.schema,
15
ELASTICSEARCH: elasticsearch.schema,
16
COUCHDB: couchdb.schema,
17
SQL_SERVER: sqlServer.schema,
18
S3: s3.schema,
19
AIRTABLE: airtable.schema,
20
// Our new integration schema
21
MYSQL: mysql.schema,
22
}
23
​
24
const INTEGRATIONS = {
25
POSTGRES: postgres.integration,
26
DYNAMODB: dynamodb.integration,
27
MONGODB: mongodb.integration,
28
ELASTICSEARCH: elasticsearch.integration,
29
COUCHDB: couchdb.integration,
30
S3: s3.integration,
31
SQL_SERVER: sqlServer.integration,
32
AIRTABLE: airtable.integration,
33
// Our new integration class
34
MYSQL: mysql.integration,
35
}
36
​
37
module.exports = {
38
definitions: DEFINITIONS,
39
integrations: INTEGRATIONS,
40
}
41
​
Copied!
We can now test our new integration from the builder frontend! Open up the budibase builder and create a new application. Go to Data Sources and click the plus icon to add a new datasource. Choose our new MySQL integration. There is no icon there for MySQL, but we will add that later on. Click MySQL and you will now see your integration options in the UI! Fill in your integration options and click Create.
You will be presented with the datasource configuration screen. You can use this screen to edit your datasource configuration should it change. Let's create a query now so we can fetch our data. Click the Create Query button.
Write your query and click the Run Query button. This will execute your query and determine the schema so budibase knows what columns you have in your table.
It works! We can now save our query and use it in the design section of the builder. This concludes the end to end for our datasource and query configuration. Completing the integration is a matter of filling out the remaining methods in the integration class. We are not going to go through all of the separate CRUD methods in the scope of this tutorial - you can see the fully completed MySQL integration here. You also do not need to implement all of the CRUD methods for an integration. It's your choice how many you want your integration to have.

Adding Our MySQL Icon

To add an icon for your integration, you must add an SVG file with the icon to packages/builder/src/components/backend/DatasourceNavigator/icons.
Create `packages/builder/src/components/backend/DatasourceNavigator/icons/MySQL.svelte` with the following contents:
1
<script>
2
export let width = "100"
3
export let height = "100"
4
</script>
5
​
6
<svg
7
{width}
8
{height}
9
viewBox="0 0 147 147"
10
fill="none"
11
xmlns="http://www.w3.org/2000/svg">
12
<path
13
d="M128.244 27.5625H83.3444L74.1569
14
45.9375H22.9688V124.031H137.812V27.5625H128.244ZM128.625
15
45.9375H92.7478L97.5621 36.75H128.625V45.9375Z"
16
fill="#2A4B59" />
17
<path
18
fill-rule="evenodd"
19
clip-rule="evenodd"
20
d="M73.5827 67.597C72.6671 67.5874 71.7543 67.6986 70.8678
21
67.9278V68.061H70.9964C71.6302 69.0199 72.3383 69.9277 73.1141
22
70.7759C73.647 71.837 74.111 72.889 74.6393 73.9502L74.7679 73.8169C75.2581
23
73.4258 75.6415 72.917 75.8825 72.3379C76.1234 71.7589 76.2141 71.1283
24
76.146 70.5048C75.8564 70.0602 75.5911 69.6001 75.3513 69.1267C74.9562
25
68.4652 74.0926 68.1345 73.5597 67.6062"
26
fill="white" />
27
<path
28
fill-rule="evenodd"
29
clip-rule="evenodd"
30
d="M139.319 125.345C134.95 125.032 130.564 125.658 126.457 127.183C125.464
31
127.578 123.875 127.578 123.742 128.836C124.275 129.365 124.339 130.214
32
124.808 130.959C125.714 132.492 126.878 133.858 128.248 134.997C129.626
33
136.058 131.028 137.11 132.488 138.038C135.07 139.632 138.001 140.555
34
140.495 142.144C141.956 143.063 143.408 144.262 144.873 145.259C145.599
35
145.787 146.058 146.637 146.986 146.977V146.775C146.712 146.039 146.374
36
145.329 145.976 144.653C145.314 143.996 144.653 143.394 143.986
37
142.737C142.043 140.171 139.72 137.917 137.096 136.053C134.974 134.592
38
130.338 132.608 129.479 130.164L129.346 130.031C130.906 129.811 132.443
39
129.454 133.94 128.965C136.186 128.372 138.24 128.506 140.56 127.913C141.621
40
127.647 143.541 126.994 143.541 126.994V125.961C142.356 124.785 141.51
41
123.204 140.266 122.097C136.876 119.139 133.264 116.447 129.461
42
114.045C127.426 112.735 124.808 111.885 122.649 110.769C121.868 110.374
43
120.558 110.181 120.099 109.524C119.022 107.943 118.121 106.248 117.412
44
104.471C115.475 100.744 113.684 96.944 112.042 93.0786C111.076 90.527
45
109.961 88.0344 108.702 85.6138C102.629 75.3049 93.8692 66.8402 83.3582
46
61.1245C80.7056 59.8389 77.8847 58.9342 74.9792 58.4372C73.3392 58.3683
47
71.7038 58.2396 70.0685 58.1753C69.0107 57.4823 68.0036 56.7147 67.055
48
55.8784C63.3202 53.5218 53.7009 48.4136 50.9493 55.1572C49.1807 59.4156
49
53.5677 63.6051 55.0836 65.7688C56.3514 67.2941 57.4683 68.9387 58.4187
50
70.6795C58.8781 71.7912 59.0067 72.9764 59.4707 74.1524C60.4281 77.1443
51
61.5648 80.0758 62.8746 82.931C63.5769 84.3429 64.3863 85.699 65.2956
52
86.9873C65.8238 87.7131 66.738 88.0347 66.9355 89.2199C66.2106 90.78 65.7036
53
92.4324 65.4288 94.1306C64.2846 97.7426 63.8637 101.545 64.19 105.32C64.5163
54
109.094 65.5835 112.768 67.3306 116.13C68.378 117.765 70.8678 121.372
55
74.2212 119.993C77.1658 118.817 76.5181 115.083 77.3633 111.812C77.5609
56
111.022 77.4276 110.503 77.8227 109.974V110.618C77.8227 110.618 79.4948
57
114.293 80.3217 116.171C82.5698 119.591 85.3631 122.618 88.5905
58
125.134C89.8767 126.245 90.9145 127.614 91.6361
59
129.153V130.339H93.1153C93.0837 129.805 92.9362 129.285 92.6832
60
128.815C92.4301 128.344 92.0775 127.935 91.6499 127.614C90.4391 126.367
61
89.33 125.024 88.3332 123.6C85.6231 119.742 83.234 115.669 81.1899
62
111.421C80.1655 109.34 79.2743 107.071 78.4337 104.99C78.0524 104.191
63
78.0524 102.983 77.4139 102.583C76.2312 103.981 75.2053 105.505 74.3544
64
107.126C73.3203 110.403 72.7195 113.8 72.5675 117.233C72.3148 117.301
65
72.4388 117.233 72.3148 117.366C70.2752 116.833 69.5586 114.61 68.8052
66
112.772C66.8219 107.009 66.6218 100.781 68.231 94.9023C68.6903 93.5242
67
70.5967 89.0821 69.825 87.7453C69.4391 86.4682 68.1666 85.7378 67.4638
68
84.7318C66.5711 83.3765 65.8024 81.9436 65.1669 80.4504C63.6372 76.7065
69
62.8701 72.5538 61.2117 68.8098C60.2956 67.0053 59.2292 65.2811 58.0236
70
63.6557C56.6915 62.031 55.5163 60.2837 54.514 58.4372C54.2707 58.0251
71
54.1215 57.5643 54.077 57.0878C54.0326 56.6113 54.0939 56.1309 54.2568
72
55.6809C54.2928 55.4547 54.4023 55.2467 54.5684 55.0889C54.7344 54.9312
73
54.9478 54.8325 55.1755 54.8081C56.0024 54.0731 58.3636 55.0056 59.1905
74
55.4099C61.4133 56.2841 63.5306 57.4059 65.5023 58.7541C66.421 59.4248
75
68.4974 61.1245 68.4974 61.1245H69.1176C71.2353 61.5839 73.624 61.2531
76
75.6085 61.8503C78.9646 62.967 82.1671 64.5011 85.1406 66.4165C93.9149
77
72.002 101.049 79.8174 105.812 89.0637C106.607 90.5842 106.942 91.9761
78
107.65 93.561C109.028 96.8133 110.764 100.125 112.152 103.3C113.372 106.43
79
114.951 109.408 116.856 112.175C117.848 113.553 121.822 114.293 123.609
80
115.023C125.17 115.557 126.703 116.17 128.202 116.86C130.453 118.239 132.7
81
119.842 134.822 121.367C135.879 122.162 139.191 123.815 139.388 125.143"
82
fill="#F3FDFF" />
83
</svg>
84
​
Copied!
Now we need to update packages/builder/src/components/backend/DatasourceNavigator/icons/index.js to include our new icon.
1
import Postgres from "./Postgres.svelte"
2
import DynamoDB from "./DynamoDB.svelte"
3
import Elasticsearch from "./Elasticsearch.svelte"
4
import MongoDB from "./MongoDB.svelte"
5
import CouchDB from "./CouchDB.svelte"
6
import S3 from "./S3.svelte"
7
import Airtable from "./Airtable.svelte"
8
import SqlServer from "./SQLServer.svelte"
9
import MySQL from "./MySQL.svelte"
10
​
11
export default {
12
POSTGRES: Postgres,
13
DYNAMODB: DynamoDB,
14
MONGODB: MongoDB,
15
ELASTICSEARCH: Elasticsearch,
16
COUCHDB: CouchDB,
17
SQL_SERVER: SqlServer,
18
S3: S3,
19
AIRTABLE: Airtable,
20
MYSQL: MySQL,
21
}
22
​
Copied!
Our icon has been added! Now when we open the datasource creation menu, the builder will contain our new icon.

Data Connector Schema Reference

Here is the total schema for budibase data connectors. This is written using the TypeScript type notation.
1
type QueryType = "string" | "fields" | "sql" | "json"
2
type FieldType = "string" | "password" | "number"
3
​
4
interface DatasourceKey = {
5
type: QueryType;
6
default: string | number | boolean;
7
required: boolean
8
}
9
​
10
interface QueryFieldConfig = {
11
type: FieldType;
12
required: boolean;
13
default: string | number | boolean;
14
}
15
​
16
interface QueryConfig = {
17
type: QueryType;
18
// Allows you to pass extra data as JSON. Good for Create/Update Queries
19
customisable?: boolean;
20
fields: Record<string, QueryFieldConfig>;
21
}
22
​
23
// The schema that you must export
24
interface IntegrationSchema = {
25
// link to documentation that will be displayed in the UI
26
docs?: string,
27
// Fields for configuring your datasource
28
datasource: Record<string, DatasourceKey>;
29
// Definitions for each of your queries
30
query: {
31
create?: QueryConfig,
32
read?: QueryConfig,
33
update?: QueryConfig,
34
delete?: QueryConfig,
35
},
36
}
Copied!

Making a Contribution

We are always excited to hear ideas from the community and to accept contributions for new budibase data connectors.
To suggest a data connector, join the discussion here - https://github.com/Budibase/budibase/discussions/891​
To contribute a data connector, raise a PR to the github repository with your new data connector! Don't hesistate to join our discord channel if you have any questions. The team will be glad to help with any issues.
​
Last modified 8mo ago