PG-promise : Query formatting issue in QueryFile

1.4k Views Asked by At

I have a normal sql insert statement where i am trying to insert UUID value. I am using pg-promise named parameters passed with object. I have been struggling with this error for hours. What is the problem in the Query format? Here is the below code that i use to execute the query from Queryfile. I'm not sure it also throws the error twice.

Source code

pgdb.one(postgresMapper.Registry.TransactionRequest.insert,{
        transaction_request_guid: transactionRequestGuid,
        transaction_request_attributes_id: docId.toString(),
      })
        .then((data) => {
          request.app.transaction_id = data.transaction_request_id;
  });

Where postgresMapper.Registry.TransactionRequest.insert is the QueryFile

Sql

INSERT INTO public.transaction_request (transaction_request_guid,transaction_request_attributes_id,createdon_utc) VALUES(${transaction_request_guid},${transaction_request_attributes_id},CURRENT_TIMESTAMP) RETURNING transaction_request_id

Console error

QueryFile { file: "D:\aud-plugin\build\sqls\insert-transaction-request.sql" options: {"debug":true,"minify":true,"compress":false,"noWarnings":false} query: "INSERT INTO public.transaction_request (transaction_request_guid,transaction_reques t_attributes_id,createdon_utc) VALUES(${transaction_request_guid},${transaction_request_attribu tes_id},CURRENT_TIMESTAMP) RETURNING transaction_request_id" } QueryFile { file: "D:\aud-plugin\build\sqls\insert-transaction-request.sql" options: {"debug":true,"minify":true,"compress":false,"noWarnings":false} query: "INSERT INTO public.transaction_request (transaction_request_guid,transaction_reques t_attributes_id,createdon_utc) VALUES(${transaction_request_guid},${transaction_request_attribu tes_id},CURRENT_TIMESTAMP) RETURNING transaction_request_id" } (node:6164) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Ty peError: Invalid query format. (node:6164) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): Ty peError: Invalid query format.

1

There are 1 best solutions below

1
On BEST ANSWER

As per this discussion, you were using more than one version of pg-promise at the same time.

You created QueryFile objects using one version of the library, and then tried to use those with a different version. And as QueryFile is an internal type, which changed its behavior between versions, thus creating the conflict on your side.