Search code examples
node.jspostgresqlknex.js

Datatypes of Knex that I can use with PostgreSQL


To clarify my question, at the moment I am creating a Migration file for a table that will be in my database. But I cannot find all the datatypes I can use, I wonder where could I find them since PostgreSQL provides a lot of datatypes. And, I wonder if I am able to use some of them.

My migration file:

exports.up = function(knex) {
  return knex.schema.createTable('organizations', function (table) {
    table.increments('id').unsigned().primary()

    table.dateTime('registeredAt').notNull()
  })
}

As seen above, I am able to use datetime but could I use, for example, cdr which is for IP addresses in v4 or v6. And also, if exists, a documentation of what maps to what would be very useful.

Also, if you are able to, a definite answer with an array of IP addresses column would be very kind of you.


Solution

  • Knex has a specificType method that accepts any valid DB column type.

    exports.up = function(knex) {
      return knex.schema.createTable('organizations', function (table) {
        table.specificType('columnName', 'tinyInt');
      })
    }