How-To Guides
Integration Guides

Work with Tables in SQL Connectors (Create Table and Show Mapping)

12min

When you set up and configure a connection with the following SQL connectors, you have the option of selecting how the data will be transferred to database tables.

When configuring the connector, make sure to select only one of the following options.

Option 1: Create Table

If you select the Create table checkbox, a default table will be created if one doesn't already exist. The table will be used to store data sent through the connector.

If you select this checkbox, make sure to unselect the Show Mapping checkbox.

Microsoft SQL Server Default Table

If you set up a connection with DB - Microsoft SQL Server or DB - Microsoft SQL Server SSL and select Create table, an existing table will be used or a new one will be created using the following commands.

SQL


MySQL Default Table

If you set up a connection with DB - MySQL or DB - MySQL SSL and select Create table, an existing table will be used or a new one will be created using the following commands.

MySQL


PostgreSQL Default Table

If you set up a connection with DB - PostgreSQL or DB - PostgreSQL SSL and select Create table, an existing table will be used or a new one will be created using the following commands.

Pgsql


Option 2: Show Mapping

If you select the Show Mapping checkbox, you can send data to a custom table in the database. This table can be configured in your preferred format and structure.

Important:

  • If you make any changes to the data type or destination table in the database, make sure to disable and enable the connector. If the connector isn't restarted, Litmus Edge will not have access to the latest table schema. This may affect the data transfer.
  • When configuring the table, there are no limitations on what data types are supported. You can put any field type into the custom table as long as this type can store data from the respective field.

Before You Begin

  • Make sure you have sufficient knowledge of SQL when configuring the mapping for the custom table. Any errors in the format will cause failures in sending data to the database.
  • The database table that will store the data from this connection will be need to be created before completing these steps. This task only maps the data that will be sent to the pre-existing table.

Configure Custom Table Mapping

To configure custom table mapping, begin by following Step 1, Step 2, and Step 3 for one of the following guides:

These guides use DeviceHub data from devices and tags to create the data that will be sent to the database. Alternatively, you can also use Analytics or the Flows Manager to create this data.

When you get to Step 4 to add the connector in Litmus Edge, configure the following parameters for the custom table:

  • Table: This is the name of the pre-existing custom table that will store the transferred data.
  • Show Mapping: Select this checkbox. See the Configure Key/Value Pairs section below to learn how to format key/value pairs.
  • Create Table: Make sure to unselect this checkbox.

Configure Key/Value Pairs

Once you select the Show Mapping checkbox, you'll be able to map the key/value pairs for the custom table.

To configure key/value pairs:

  1. From the Add a connector or Edit connector dialog box, select the Show Mapping checkbox. Make sure the Create table checkbox is not selected. The Key/Value section appears.

    Show Mapping checkbox
    Show Mapping checkbox
    
  2. In the Key field, enter the name of the first column in the table.
  3. In the Value field, enter the value name that will be stored in the first column in the following format: {{.value_name}}. Replace value_name with the corresponding key value of the JSON. See the example below.
  4. Click +Add. The key/value pair is added to the mapping for the connector.
  5. Continue adding columns and corresponding values for your table.

Mapping Example

You have the following data in JSON format.

{“deviceName”: “PLC1”, “timestamp”: 1239423823, "value": 123}, {“deviceName”: “PLC1”, “timestamp”: 1247382948, "value": 545}, {“deviceName”: “PLC1”, “timestamp”: 1294859324, "value": 787}

You have created the following database table.

Device Name

Timestamp

Data Value







The Show Mapping section would be formatted as shown below.

Show Mapping formatting example
Show Mapping formatting example


The database table would be updated with the data as shown below.

Device Name

Timestamp

Data Value

PLC1

1239423823

123

PLC1

1247382948

545

PLC1

1294859324

787