KnexJS with postgreSQL returns 所有数据都是字符串,不考虑来自数据库的数据类型

KnexJS with postgreSQL returns all data as string, does not respect the data type that comes from the database

我在与 postgreSQL 一起使用的 KnexJs 中遇到问题,但每次我创建一个 select 时,knex 都会将 table 中的所有数据作为字符串回答,这不是案例,因为有些字段是数字和 knex 像字符串一样传递我,有人会知道如何帮助我,我很绝望。

Select 奈克斯

function getDeadlines(){
    let query = knex(prazo.getTableName())
                    .select(prazo.properties.idDeadline.getDbProperty(), prazo.properties.deadline.getDbProperty())
                    .orderBy(prazo.properties.deadline.getDbProperty(), 'desc')
    return query
}

响应knexjs代码

{
    deadlines: [
      {
        cd_prazo_pk_36: "1", //(Is a numeric in database table)
        ds_prazo_36: "A Vista"
      },
      {
        cd_prazo_pk_36: "2",  //(Is a numeric in database table)
        ds_prazo_36: "7 Dias"
      },
      {
        cd_prazo_pk_36: "4", //(Is a numeric in database table)
        ds_prazo_36: "21 Dias"
      },
      {
        cd_prazo_pk_36: "3", //(Is a numeric in database table)
        ds_prazo_36: "14 Dias"
      }
   ]
}

cd_prazo_pk_36 这不是字符串,是数字

连接

    development: {
    client: 'pg',
    connection: {
      host : 'localhost',
      user : 'postgres',
      password : '123',
      database : 'testing',
      charset: 'utf8'
    },
    useNullAsDefault: true
  },

我已经谢谢你了

node-postgres will convert a database type to a JavaScript string if it doesn't have a registered type parser for the database type. Furthermore, you can send any type to the PostgreSQL server as a string and node-postgres will pass it through without modifying it in any way.

https://node-postgres.com/features/types

Knex 使用 node-postgres 数据库驱动程序访问 postgresql。

您可以使用 https://github.com/brianc/node-pg-types 覆盖每种数据类型的默认解析器。