pino-postgres
Advanced tools
Comparing version 0.0.7 to 0.0.8
16
index.js
@@ -12,7 +12,5 @@ #! /usr/bin/env node | ||
class PinoTransform extends Transform { | ||
constructor (schema, table, column, sql) { | ||
constructor (opts, sql) { | ||
super() | ||
this.table = table | ||
this.schema = schema | ||
this.column = column | ||
this.opts = opts | ||
this.sql = sql | ||
@@ -22,2 +20,3 @@ } | ||
_transform (chunk, encoding, callback) { | ||
const { schema, table, column, passThrough } = this.opts | ||
const content = chunk.toString('utf-8') | ||
@@ -28,7 +27,7 @@ let log = {} | ||
} catch (err) { | ||
return callback(null, `${chunk}\n`) | ||
return callback(null, passThrough ? `${chunk}\n` : null) | ||
} | ||
this.sql` | ||
INSERT INTO ${this.sql(this.schema)}.${this.sql(this.table)} (${this.sql(this.column)}) VALUES (${this.sql.json(log)}) | ||
INSERT INTO ${this.sql(schema)}.${this.sql(table)} (${this.sql(column)}) VALUES (${this.sql.json(log)}) | ||
ON CONFLICT DO NOTHING; | ||
@@ -39,3 +38,3 @@ ` | ||
console.error('error in pino-postgres transform', err) | ||
callback(null, `${chunk}\n`) | ||
callback(null, passThrough ? `${chunk}\n` : null) | ||
}) | ||
@@ -57,2 +56,3 @@ } | ||
.option('--debug', 'debug postgres client', false) | ||
.option('--pass-through', 'pass logs through', false) | ||
@@ -78,3 +78,3 @@ const opts = program.parse(process.argv).opts() | ||
const sql = postgres(opts.connection, postgresOpts) | ||
const transport = new PinoTransform(opts.schema, opts.table, opts.column, sql) | ||
const transport = new PinoTransform(opts, sql) | ||
transport.on('end', sql.end) | ||
@@ -81,0 +81,0 @@ pipeline(process.stdin, split(), transport, process.stdout, err => { |
{ | ||
"name": "pino-postgres", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Pino transport for Postgres", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4460