代码之家  ›  专栏  ›  技术社区  ›  Spandana Satyanarayana

winston postgresql自定义sql/tableName不工作

  •  1
  • Spandana Satyanarayana  · 技术社区  · 8 年前
    const logger = new (winston.Logger)({
      transports : [
        new winston.transports.PostgreSQL({
          connString :   'xxxxxxxxxxx',
          schema : 'public',
          //tableName : 'logEntry',
          customSql:'INSERT INTO public."logEntry"(logLevel, msg, meta) VALUES ($1, $2, $3);',
        })
      ];
    });
    

    数据未插入表中,我在控制台中收到一条警告:

    不赞成未经处理的承诺拒绝。将来,未处理的承诺拒绝将终止节点。具有非零退出代码的js进程。

    谁能告诉我这个代码有什么问题吗?

    2 回复  |  直到 8 年前
        1
  •  0
  •   David R    8 年前

    logger.transports.PostgreSQL.on('error', err => 
        console.log('Error while inserting data')
    ); 
    

    希望这有帮助!。

        2
  •  0
  •   Spandana Satyanarayana    8 年前

    我使用启用了时间戳的sequelize创建了表,在这里手动插入数据意味着它不会添加createdAt列,这会导致问题。 更换 customSql:'INSERT INTO public。“logEntry”(logLevel,msg,meta)值($1,$2,$3);', 具有 customSql:'插入公共。“logEntry”(“logLevel”,msg,meta,“createdAt”)值($1,$2,$3,CURRENT_TIMESTAMP);', 解决了这个问题。 非常感谢。