筆記:Node.js Postgresql踩坑

記錄一次踩坑

利用node.js裏的pg庫去查詢日期數據時,因爲node.js無timestamp類型,自動轉date類型丟失三位精度node

數據庫記錄數據:2019-02-01 05:11:11.173031數據庫

node查出數據:2019-02-01T05:11:11.173Zui

解決方案

改變pg庫的轉換方式spa

const pg = require('pg');
const types = pg.types;
// 設置直接返回string類型的數據而不是date
types.setTypeParser(1114, function(stringValue) {
  return stringValue;
});
複製代碼
相關文章
相關標籤/搜索