loopbackio/loopback-connector-postgresql

value "96698647964" is out of range for type integer

arvindknit31 opened this issue · 6 comments

I am getting error "value "96698647964" is out of range for type integer" in loopback4 and latest l@loopback/cli with postgresql 12 on windows 10, please suggest me what should i do?

My user.model.ts as follows -->

import {Entity, model, property} from '@loopback/repository';

@model()
export class User extends Entity {
@Property({
type: 'number',
id: true,
generated: true,
})
id?: number;

@Property({
type: 'string',
})
name?: string;

@Property({
type: 'string',
required: true,
})
email: string;

@Property({
type: 'string',
required: true,
})
username: string;

@Property({
type: 'string',
required: true,
})
password: string;

@Property({
type: 'number',
required: true,
})
phone: number;

constructor(data?: Partial) {
super(data);
}
}

export interface UserRelations {
// describe navigational properties here
}

export type UserWithRelations = User & UserRelations;

My package.json as follows ----->

{
"name": "smgmt",
"version": "1.0.0",
"description": "Demo Project",
"keywords": [
"loopback-application",
"loopback"
],
"main": "index.js",
"engines": {
"node": ">=8.9"
},
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"clean": "rimraf dist .tsbuildinfo",
"pretest": "npm run clean && npm run build",
"migrate": "node ./dist/migrate",
"start": "npm run build && node -r source-map-support/register .",
"prepare": "npm run build"
},
"repository": {
"type": "git"
},
"author": "",
"license": "",
"files": [
"README.md",
"index.js",
"index.d.ts",
"dist",
"src",
"!/tests"
],
"dependencies": {
"@loopback/boot": "^1.7.1",
"@loopback/context": "^1.25.1",
"@loopback/core": "^1.12.1",
"@loopback/openapi-v3": "^1.11.0",
"@loopback/repository": "^1.17.0",
"@loopback/rest": "^1.25.1",
"@loopback/rest-explorer": "^1.4.7",
"@types/mocha": "^5.2.7",
"loopback-connector-postgresql": "^3.8.1"
},
"devDependencies": {
"@loopback/build": "^3.0.1",
"@loopback/testlab": "^1.10.1",
"@types/node": "^10.17.13",
"rimraf": "^3.0.0",
"source-map-support": "^0.5.16",
"typescript": "~3.7.4"
}
}

@arvindknit31, looking at this article: https://www.postgresqltutorial.com/postgresql-data-types/, it says:

Integer ( INT) is a 4-byte integer that has a range from -2,147,483,648 to 2,147,483,647.

I guess this is an expected behavior that your number provided above is out of range.

Hi @dhmlau thanks for reply, but what about if my primary key which is also integer and auto increment reach to this number?

Also postgres support bigint then why we can't use it'?

https://www.postgresql.org/docs/current/datatype.html

@arvindknit31 The dataType setting should work:

@property({
  type: 'number',
  id: true,
  generated: true,
  postgresql: {
    dataType: 'bigint',
  },
})
id?: number

OR

@property({
  type: 'number',
  id: true,
  generated: true,
  settings: {
    postgresql: {
      dataType: 'bigint',
    },
  },
})
id?: number;

^ Both are effectively identical

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@Column({ nullable: true, type: 'bigint', generated: true, }) id: number;