0

我在使用 PostgreSQL 数据库运行 Sails 应用程序时遇到问题。我需要插入一个 11 位整数,但我找不到一种简单的方法来为此调整我的模型。

编辑 1 这里是一个模型的例子:

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

module.exports = {

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

有没有办法(使用 ORM)在 Postgre 中将该整数更改为 BIGINT,所以我在插入时没有得到ERROR: integer out of rage

4

4 回答 4

2

据此,你应该能够将“bigint”定义为类型

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

还支持 float、real、smallint 等。. .

于 2015-03-20T13:37:12.027 回答
1

您的值作为字符串返回的原因是因为PostgreSQL 的 BIGINT 最大值(2^63-1 = 9223372036854775807) 远大于 Javascript 的Number.MAX_SAFE_INTEGER (2^53 - 1 = 9007199254740991) 所以如果 Sails / Waterline ORM 要一直将您的返回值转换为整数,有可能破坏事物。

所以,每次都返回一个字符串会更安全。

于 2016-07-30T12:37:37.703 回答
1

在我的情况下,将类型定义为 bigint 不起作用。在模型中创建条目时出现验证错误。

但是,我给出了以下属性,

type: string,
numeric: true,
minLength: 10

这已经足够好了,但不是我想要的。

于 2015-12-14T00:02:15.970 回答
0

通过使用以下设置属性,我能够使其工作:

type: 'ref',
columnType: 'int8',
于 2020-03-16T05:01:19.073 回答