You may want your applications to deal with information available in external databases. OutSystems allows you to do it and be able to consume your external database entities as any other entity in your application.
To connect to an external database and use its data in your application:
- Define a connection to the external database;
- Use an extension module to define entities for tables or views in the external database;
- Configure your extension to use the database connection;
- In your application, add a dependency to the extension;
- Use the entities of the extension as any other entity.
For a list of supported database engines using this procedure, see the System Requirements. In case you need to select the database based on runtime data, use the DatabaseConnection_SetConnectionStringForSession action of the PlatformRuntime API.
In the Sales app, we want to list the Order records with the Customer and Product information, and allow users to modify them. The data is stored in the customer, order and product tables of an external database called salesdb.
To connect to the salesdb database:
- Open the environment management console and open Administration > Database Connection;
- Set up a new database connection to your external database. The user defined in this database connection determines the privileges of access to the data, namely the ability to read, create, update or delete data.
Call it SalesDB Connection;
- To map the database tables to entities you need to implement an extension module. Create a new extension and name it SalesDB_Connector;
- Right-click on the Entities folder and choose Connect to External Table or View...;
- Follow the steps in the interface to connect to the customer, order and product tables;
- Make sure you choose SalesDB Connection and salesdbwhen you are prompted to select database connection and database;
In the Logical Database Name field, type
Logical SalesDB. As result, the customer, order and product entities are defined in the extension;
Click the 1-Click Publish button to publish it;
- After publishing the extension, you can configure the database connection that will be used by the logical database. In the dialog above, click Configure;
In the environment management console, select the SalesDB Connection to be used by the extension;
To use the extension, add a dependency to it in your application. The entities from the extension module became available after this. Now, you can create the screens that list and modify order records;