* Decimal type, variable precision, take length as specified by user
| 326 | * Decimal type, variable precision, take length as specified by user |
| 327 | */ |
| 328 | class DECIMAL extends NUMBER { |
| 329 | /** |
| 330 | * @param {string|number} [precision] defines precision |
| 331 | * @param {string|number} [scale] defines scale |
| 332 | */ |
| 333 | constructor(precision, scale) { |
| 334 | super(typeof precision === 'object' && precision || { precision, scale }); |
| 335 | } |
| 336 | toSql() { |
| 337 | if (this._precision || this._scale) { |
| 338 | return `DECIMAL(${[this._precision, this._scale].filter(_.identity).join(',')})`; |
| 339 | } |
| 340 | return 'DECIMAL'; |
| 341 | } |
| 342 | validate(value) { |
| 343 | if (!Validator.isDecimal(String(value))) { |
| 344 | throw new sequelizeErrors.ValidationError(util.format('%j is not a valid decimal', value)); |
| 345 | } |
| 346 | return true; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // TODO: Create intermediate class |
| 351 | const protoExtensions = { |
nothing calls this directly
no outgoing calls
no test coverage detected