brianc / node-pg-query-stream

Query results from node-postgres as a readable (object) stream
MIT License
312 stars 37 forks source link

Should work with a QueryConfig #23

Open abenhamdine opened 7 years ago

abenhamdine commented 7 years ago

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.

brianc commented 7 years ago

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

q42jaap commented 5 years ago

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)