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?

2
  • Could you show us your code? Commented Mar 19, 2015 at 16:27
  • pastebin.com/8sD0Xwv4 Commented Mar 19, 2015 at 17:12

4 Answers 4

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 . . .

Sign up to request clarification or add additional context in comments.

1 Comment

Canonical link as file keeps changing :) github.com/balderdashy/sails-postgresql/blob/…
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.

Comments

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.

Comments

0

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

type: 'ref',
columnType: 'int8',

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.