Skip to content
Advertisement

Knex.js with Postgres returns boolean fields as “0” or “1” instead of booleans

When I query with Knex.js a Postgres database boolean fields it returns the result as "0" or "1" (as strings) instead of the boolean values true and false.

Is there a way to make Knex/Postgres return boolean fields automatically as boolean values?

EDIT: I’m using Knex with node-postgres, here are my table definitions:

JavaScript

Advertisement

Answer

I needed to use the pg.types module:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement