1

I am using following code in loopback 4 to have number (float) field, but I am not getting float in my DB:

@property({
  type: 'number',
  jsonSchema: {
    format: 'float',
  },
})
Field: number;

I am using MySQL database and loopback migrate with int(11) type (docs just have number)

Any Suggestions?

U-Dev
  • 1,296
  • 5
  • 19

2 Answers2

3

You can use dataType as:

@property({
  type: 'number',
  dataType: 'FLOAT'
})
Field: number;
Inyourface
  • 532
  • 4
  • 12
0

For Loopback 4, default migration reads this from database specific settings.

Float can be used like this for postgresql connector.

@property({
    type: 'number',
    postgresql: {
      dataType: 'float',
      precision: 20,
      scale: 4,
    },
})
rating?: number;
Shubham P
  • 1,164
  • 4
  • 18