loopbackio/loopback-connector-postgresql

Error: Postgresql column as jsonb returning data as string using createAll() method

saurabh2608 opened this issue · 2 comments

Updated the latest version of loopback connector postgresql, used the createAll[] method for bulk insert data in the project.The model(table) for which were working, a property /column was Jsonb so the data was saved but the data it is returning was string but not jsonb.

Example:
SQL query for a

table:CREATE TABLE main.tasks ((((
id uuid DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL,
archived boolean DEFAULT false,
board_id uuid NOT NULL,
created_by uuid,
created_on timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
deleted boolean DEFAULT false,
deleted_by uuid,
deleted_on timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
description text,
group_id uuid NOT NULL,
modified_by uuid,
modified_on timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
name character varying(300) NOT NULL,
parent_task_id uuid,
sequence_number double precision,
meta_data jsonb,
message_count integer DEFAULT 0,
message_file_count integer DEFAULT 0,
serial_number integer,
serial_prefix character varying,
previous_task_id uuid,
next_task_id uuid
);

This is a sample code:
const createdTask = await this.taskRepository.createAll(tasks, {
noAudit,
});

Input Data of Tasks:

[
{
"name": "New Item1",
"description": null,
"archived": false,
"sequenceNumber": 0,
"boardId": "1",
"groupId": "1",
"metaData": {
"tempId": "1"
}
},
{
"name": "New Item1",
"description": null,
"archived": false,
"sequenceNumber": 0,
"boardId": "2",
"groupId": "2",
"metaData": {
"tempId": "2"
}
}
]
Once the data is saved the return output is below:

Output Data of Task: [
{
"deleted": false,
"createdOn": "2023-01-17T15:32:12.456Z",
"modifiedOn": "2023-01-17T15:32:12.456Z",
"createdBy": "5",
"modifiedBy": "59",
"id": "1",
"name": "New Item1",
"description": null,
"archived": false,
"sequenceNumber": 0,
"boardId": "1",
"groupId": "1",
"metaData": "{"tempId":"1"}",
"messageCount": 0,
"messageFileCount": 0,
"serialNumber": null,
"serialPrefix": null,
"previousTaskId": null,
"nextTaskId": null
},
{
"deleted": false,
"createdOn": "2023-01-17T15:32:12.457Z",
"modifiedOn": "2023-01-17T15:32:12.457Z",
"createdBy": "59",
"modifiedBy": "59",
"id": "2",
"name": "New Item1",
"description": null,
"archived": false,
"sequenceNumber": 0,
"boardId": "2",
"groupId": "2",
"metaData": "{"tempId":"2"}",
"messageCount": 0,
"messageFileCount": 0,
"serialNumber": null,
"serialPrefix": null,
"previousTaskId": null,
"nextTaskId": null
}
]

The error occurred is metadata properties existing in input should be same for output but it is returning in string where at input time it was in object type.

Issue is actually from https://github.com/loopbackio/loopback-datasource-juggler. It is not retuning the full serialized instance.

Fixed here.