Skip to content

DbClientPg

do- edited this page Nov 3, 2023 · 74 revisions

DbClientPg is a DbClient descendant for PostgreSQL: a wrapper above pg for using in doix Jobs.

Methods

See parent class

putStream (tableName, columns, options)

This asynchronous method returns a binary Writable stream corresponding to a COPY FROM STDIN statement.

The result is an instance of a class provided by pg-copy-streams.

const {db} = this

await new Promise ((ok, fail) => {

  const os = await db.putStream (
    'payments'
    , ['article', 'amount'] // mandatory
    , {                     // optional; names are case insensitive
//    FORMAT: 'text',
//    FREEZE: false,
//    DELIMITER: '\t',
//    NULL '',
//    HEADER: false,
//    QUOTE: '"',
//    ESCAPE: '\',
//    FORCE_QUOTE: ['article'], // '*'
//    FORCE_NOT_NULL: ['article'],
//    FORCE_NULL: ['article'],
//    ENCODING: 'utf-8'    
    }
  )

  os.on ('error', fail)
  os.on ('finish', ok)

  fs.createReadStream ('/tmp/payments.txt').pipe (os)

}

Clone this wiki locally