Connecting Data Sources
Relevant source files
The following files were used as context for generating this wiki page:
Budibase applications can connect to a variety of external and internal data sources, which is a core feature for building powerful internal tools, forms, and portals. The platform is designed to pull data from multiple sources, including SQL databases like PostgreSQL and MySQL, NoSQL databases like MongoDB and CouchDB, and REST APIs. This allows developers to build applications on top of existing data infrastructure without starting from scratch.
The integration system is modular and extensible, with each data source type being handled by a specific integration module. These modules conform to a common interface, ensuring consistent behavior for operations like querying, creating, reading, updating, and deleting data across different sources.
Sources: README.md
Architecture Overview
The data source integration system is managed within the packages/server/src/integrations directory. The central point of this system is index.ts, which aggregates all available integration definitions into a single exported object. Each data source (e.g., PostgreSQL, MongoDB, REST) has its own file that defines its specific implementation, including connection logic, query methods, and configuration schema.
This diagram illustrates how individual integration modules are combined into the main integrations export.
Common Integration Interface
All data source integrations must implement the Integration interface. This ensures that the Budibase server can interact with any data source in a standardized way.
The key methods of the Integration interface are:
| Method | Description |
|---|---|
query(query) | Executes a query against the data source. The structure of the query object varies by integration. |
create(query) | Creates a new record in the data source. |
read(query) | Reads a single record from the data source. |
update(query) | Updates an existing record. |
delete(query) | Deletes a record. |
validate(config) | Validates the provided data source configuration to ensure a connection can be made. |
getSchema(config) | Retrieves the schema (e.g., tables and columns for SQL, collections for MongoDB) from the data source. |
Sources: packages/server/src/integrations/index.ts:31-48
Datasource Configuration
A Datasource document stores the configuration for a connection to a specific data source within a Budibase workspace.
| Field | Type | Description |
|---|---|---|
_id | string | The unique identifier for the data source document. |
name | string | A user-friendly name for the data source. |
type | string | The type of the data source, e.g., bbinternal, postgresql, mongodb. |
plus | boolean | Indicates if this is a "Datasource Plus" type, which has a more structured definition. |
config | object | An object containing the specific connection details and credentials for the data source. The structure of this object is defined by each integration's schema. |
Sources: packages/types/src/documents/workspace/datasource.ts:4-15
Integration Implementations
PostgreSQL
The PostgreSQL integration allows Budibase to connect to and query PostgreSQL databases. It uses the pg (node-postgres) library to handle connections and execute queries.
Sources: packages/server/src/integrations/postgres.ts:11
Configuration
The config object for a PostgreSQL data source requires the following properties:
| Property | Type | Description |
|---|---|---|
host | string | The hostname of the PostgreSQL server. |
port | number | The port number of the PostgreSQL server. |
database | string | The name of the database to connect to. |
user | string | The username for authentication. |
password | string | The password for authentication. |
ssl | boolean | Whether to use SSL for the connection. |
Sources: packages/server/src/integrations/postgres.ts:15-22
Operations
The query method for PostgreSQL executes a raw SQL statement. The SQL is passed in the query.sql property. This provides flexibility to perform any operation supported by the database.
The following diagram shows the sequence of a query operation for PostgreSQL.
MongoDB
The MongoDB integration connects to a MongoDB database or cluster using a connection string. It leverages the official mongodb driver.
Sources: packages/server/src/integrations/mongodb.ts:11
Configuration
| Property | Type | Description |
|---|---|---|
connectionString | string | The MongoDB connection string URI. |
writeConcern | string | The write concern for database operations. |
readConcern | string | The read concern for database operations. |
Sources: packages/server/src/integrations/mongodb.ts:15-22
Operations
The query method for MongoDB executes an aggregation pipeline. The pipeline stages are passed as an array in the query.pipeline property. This allows for complex data transformation and analysis directly within the database. Other methods like create, read, update, and delete perform standard document operations.
Sources: packages/server/src/integrations/mongodb.ts:50-61
REST API
The REST integration allows Budibase to interact with any RESTful web service. It uses the axios library to make HTTP requests.
Sources: packages/server/src/integrations/rest.ts:12
Configuration
The configuration for a REST data source is flexible and depends on the query being made. Core properties are defined at the query level rather than the data source level.
| Property | Type | Description |
|---|---|---|
url | string | The endpoint URL for the request. |
method | string | The HTTP method (e.g., GET, POST, PUT, DELETE). |
headers | object | Key-value pairs for request headers. |
queryString | string | The URL query string. |
requestBody | object | The JSON body for POST, PUT, or PATCH requests. |
Sources: packages/server/src/integrations/rest.ts:16-23
Query Flow
The query method constructs and sends an HTTP request based on the provided parameters.
Summary
Budibase's data source integration system is built on a modular, interface-driven architecture. This design allows for consistent interaction with a wide variety of data backends, from traditional SQL databases to modern NoSQL stores and REST APIs. By centralizing the integration logic and enforcing a common Integration contract, the system is both robust and easily extensible to support new data sources in the future.
Sources: README.md, packages/server/src/integrations/index.ts