Search code examples
loopbackjsstrongloop

Decimal type in Loopback


How do you define a decimal(10,2) in Loopback? I've looked around the api and examples and I cannot get it to work. It just keeps creating a decimal(10,0). columnName does affect the output but precision and scale are not set. I've also tried "precision" instead of "dataPrecision"; still no luck.

"Amount": {
  "type": "Number",
  "required": true,
  "dataPrecision": 8,
  "dataScale": 2
  "mysql": {
    "columnName": "Amount",
    "dataType": "DECIMAL",
    "dataPrecision": 8,
    "dataScale": 2
  }
}

Solution

  • For model that use mysql connector, this should create column with decimal(10,2) type

    "amount": {
      "type": "number",
      "dataType": "decimal",
      "precision": 10,
      "scale": 2
    }