node-pg-query-stream icon indicating copy to clipboard operation
node-pg-query-stream copied to clipboard

Should work with a QueryConfig

Open abenhamdine opened this issue 7 years ago • 2 comments

Hi Brianc, and thx for this great module !

Unlike pg.Client, QueryStream doesn't seem to work when a QueryConfig is passed, ie an object as :

{
    text : 'SELECT * FROM foo WHERE bar =$1,
    values : [1]
}

I get the following error :

Unhandled rejection TypeError: "string" must be a string, Buffer, or ArrayBuffer
    at Function.byteLength (buffer.js:363:11)
    at module.exports.Writer.addCString (C:\node-projects\payroll-app\node_modules\buffer-writer\index.js:57:22)
    at Connection.parse (C:\node-projects\payroll-app\node_modules\pg\lib\connection.js:212:6)
    at module.exports.Cursor.submit (C:\node-projects\payroll-app\node_modules\pg-query-stream\node_modules\pg-cursor\index.js:21:7)
    at Client._pulseQueryQueue (C:\node-projects\payroll-app\node_modules\pg\lib\client.js:298:24)
    at Client.query (C:\node-projects\payroll-app\node_modules\pg\lib\client.js:326:8)

Is it a bug or a this feature is missing ?

Thx by advance.

abenhamdine avatar Mar 01 '17 17:03 abenhamdine

It's just a missing feature. :/ I need to support that, just haven't had the time yet.

brianc avatar Aug 07 '17 02:08 brianc

I'm using sql-template in my source code which is really nice, so having this feature would be a big bonus. As a workaround I'm currently using:

  const {text, values} = SQL`
      SELECT
        event_id,
        user_id,
        data->>'sessionDateTime' AS session_date_time,
        data
      FROM event
      WHERE data->>'sessionDateTime' >= ${beginDateTime}
        AND data->>'sessionDateTime' <= ${endDateTime}
    `;
  const query = new QueryStream(text, values)

q42jaap avatar Mar 07 '19 08:03 q42jaap