0

I'm having issues with a Sails application running with a PostgreSQL database. I needed to insert an 11 digits integer, but I can't find a simple way to tweak my models for this.

Edit 1 here is an example of a model :

/**
 * Phone.js
 *
 * @docs        :: http://sailsjs.org/#!documentation/models
 */

module.exports = {

    attributes: {
        number: {
            type: 'integer',
            required: true,
            minLength: 9
        }
    }
};

Is there a way (using the ORM) to change that integer into a BIGINT in Postgre so I don't get ERROR: integer out of rage when inserting?

PatJ
  • 5,996
  • 1
  • 31
  • 37
Raed
  • 519
  • 1
  • 6
  • 23

4 Answers4

2

According to this, yo should just be able to define "bigint" as the type

https://github.com/balderdashy/sails-postgresql/blob/master/lib/utils.js#L241

also supports float, real, smallint ect . . .

Meeker
  • 5,979
  • 2
  • 20
  • 38
  • Canonical link as file keeps changing :) https://github.com/balderdashy/sails-postgresql/blob/f0c92f5d2ca6d654d520034c90a90562e3b5fb6c/lib/utils.js#L225 – Wulf Solter Jul 06 '16 at 01:18
1

Defining type as bigint didn't work in my case. I was getting an error in validation while creating an entry in the model.

However, I gave the following properties,

type: string,
numeric: true,
minLength: 10

It was good enough but not exactly what I wanted.

risingStar
  • 300
  • 2
  • 7
1

The reason your value is returned as a string is because PostgreSQL's maximum value for BIGINT (2^63-1 = 9223372036854775807) is considerably bigger than Javascript's Number.MAX_SAFE_INTEGER (2^53 - 1 = 9007199254740991) so if Sails / Waterline ORM were to cast your returned value as an integer all the time there is a possibility of breaking things.

So, it's safer to return a string every time.

Wulf Solter
  • 717
  • 6
  • 19
0

I was able to get it to work by setting the attributes with the following:

type: 'ref',
columnType: 'int8',
user2830432
  • 222
  • 2
  • 4