jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
446 stars 63 forks source link

Error No 'sql' statement provided after updating to 1.0.0 #30

Closed ghost closed 4 years ago

ghost commented 5 years ago

Hello,

After updating to version 1.0.0 (I was using beta) this error occurs when I try to make a transaction:

No 'sql' statement provided. at error (/var/task/build/node_modules/data-api-client/index.js:54:35) at parseSQL (/var/task/build/node_modules/data-api-client/index.js:60:5) at Object.query (/var/task/build/node_modules/data-api-client/index.js:303:15) at commit (/var/task/build/node_modules/data-api-client/index.js:421:30) at process._tickCallback (internal/process/next_tick.js:68:7)

transaction.query(
      `INSERT INTO ${TABLE_NAME} (${keys}) VALUES(${params})`,
      objToInsert
    );
ghost commented 5 years ago

I'm using node 10

ghost commented 5 years ago

I believe the error is occurring because in transaction the "args" is an array of array, then it fails here:

typeof args[0] === 'string' ? args[0]
  : typeof args[0] === 'object' && typeof args[0].sql === 'string' ? args[0].sql
  : error('No \'sql\' statement provided.')
jeremydaly commented 5 years ago

Thanks for the report @engfilipe. I'll investigate this.

KrishnaMuddi commented 4 years ago

I had the same issue while using transactions. After investigating, found that args was coming in as Nested array in code.

const query = async function(config,...args) {

Flattening the array with the below code will work for both transactions and queries.

const query = async function(config,..._args) {
    var args = [].concat.apply([], _args);
...

Not sure about batches since there is a comment that says Deprecated this since it was collapsing batches. Any suggestion on how do we use it for transactions without getting sql error.

jeremydaly commented 4 years ago

I see the problem here. I removed the flattening because it was causing an issue with something else, but it looks like I'll need to add it back in and make it conditional somehow. Thanks for catching this!

jeremydaly commented 4 years ago

Fixed in v1.0.1.