Search code examples
postgresqlbooleantoggleknex.js

How do you toggle a boolean in a postgres table using knex in one query?


Is it possible to toggle a boolean value in a postgres table using knex in a single query and return the new value?


Solution

  • await knex('table').update({ 
        boolCol: knex.raw('NOT ??',  ['boolCol]) 
      }).returning('boolCol');