[V5.0.2 or later]

Discovering models from relational databases

You can use API Designer to create models from existing database tables. This process is called discovery and is supported by data source connectors for: MySQL, Oracle, PostgreSQL, and SQL Server.

Before you begin

Before you begin, you must install the developer toolkit on your local machine. For details, see Installing the toolkit.

You must also do the following:

  1. Create a LoopBack project. For more information, see Tutorial: Creating a LoopBack project from the command line or .Creating new projects with API Designer.
  2. Add the project to API Designer. For more information, see Adding an existing project to API Designer.
  3. Create a data source of one of the supported connectors listed in the following section. For more information, see Tutorial: Creating a model and a data source in the API Designer.

About this task

API Designer can create models based on an existing database schema. Doing this will create a model for each table, and a property in the model for each column in the table.

The following data source connectors support this feature:

  • MySQL
  • Oracle
  • PostgreSQL
  • SQL Server

For more information on how model discovery works programmatically and the LoopBack discovery API, see Discovering models from relational databases.

Procedure

  1. Click Data Sources.
  2. If the data source is one of the supported types listed above, the Discover Models option will be available. Click Discover Models. Alternatively, click the data source from which you want to discover models, and in the data source details page, click Discover Models Discover Models.
  3. The Discover Models page opens. It lists all the tables in the database to which the data source is connected, and the associated schema for each table.
  4. Select the check box for each table for which you want to create models. When you select a table, the Select Properties dialog appears, showing the name and type of each property to be created, and whether the property is required and an ID property. By default, each model will be created with a property for each column in the table, so all the properties are selected.
  5. In the Select Properties dialog, deselect any properties you don't want to create, and click Select.
  6. Follow step 5 for each model you want to create.
  7. Click Generate.

Results

API Designer creates a model for each of the selected tables. Each model has a property for each selected column in the table.