The JSONB data type stores JSON (JavaScript Object Notation) data as a binary representation of the JSON value. We have the attached plugin to handle JSONB and UUID data format in Postgres Database. The attached plugin is used after the mapping and it looks at the fields that require jsonb and UUID data and properly handles the insert.
- Use the attached plugin and copy paste the code from the attached file in the custom plugin.
- Change the database connection info name and tablename:
- In line no. 45: String databaseInfoName = "MyPostgresDBInfo";
- Change the databaseInfoName to the database Info name of the entity corresponding to the database in the environment.
- Change the Postgres schema name in line 46: String schemaName = "myschemaName";
- Change the tablename in line 47: String tablename = "myTableName";
- Enter the JSONB and UUID column names:
- In line no. 48, enter the JSONB column name: String[] jsonColumnName = {"myjsonbfieldname"};
- In case you have more than one jsonb column, you can simply add the column name with comma separator. For ex: String[] jsonColumnName = {"member","anotherJsonbColumn"
}; - In line no. 49, enter the UUID column name: String[] uuidColumnName = {"myUUIDfielldname"};
- In case you have more than one UUID columns, you can simply add the column name with comma separator. For ex: String[] uuidColumnName = {"id","parentid"};
- In mapping, do not filter the UUID columns, just leave them unmapped and the plugin will automatically generate the UUID values.
- Run this plugin after mapping activity, and the data should be inserted into the database.
The flow should be same, only thing we need to change is to use the plugin as the target activity as shown below.
In the above flow snapshot, in the map (see below key value pair), I have hard coded a jsonb value in the "member" field (just to test) and the second activity is the plugin that inserts the data into the postgres table.
To create the custom plugin go to Configure > Extensions > Custom Plugin, click on new, give name and description and insert the attached code in the script box as shown here and then use this plugin in the flow.
Change the values in the lines shown here. Sample screenshot:
Attached custom plugin code.
Comments
0 comments
Article is closed for comments.