* A boolean / tinyint column, depending on dialect
| 377 | * A boolean / tinyint column, depending on dialect |
| 378 | */ |
| 379 | class BOOLEAN extends ABSTRACT { |
| 380 | toSql() { |
| 381 | return 'TINYINT(1)'; |
| 382 | } |
| 383 | validate(value) { |
| 384 | if (!Validator.isBoolean(String(value))) { |
| 385 | throw new sequelizeErrors.ValidationError(util.format('%j is not a valid boolean', value)); |
| 386 | } |
| 387 | return true; |
| 388 | } |
| 389 | _sanitize(value) { |
| 390 | if (value !== null && value !== undefined) { |
| 391 | if (Buffer.isBuffer(value) && value.length === 1) { |
| 392 | // Bit fields are returned as buffers |
| 393 | value = value[0]; |
| 394 | } |
| 395 | const type = typeof value; |
| 396 | if (type === 'string') { |
| 397 | // Only take action on valid boolean strings. |
| 398 | return value === 'true' ? true : value === 'false' ? false : value; |
| 399 | } |
| 400 | if (type === 'number') { |
| 401 | // Only take action on valid boolean integers. |
| 402 | return value === 1 ? true : value === 0 ? false : value; |
| 403 | } |
| 404 | } |
| 405 | return value; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | |
| 410 | BOOLEAN.parse = BOOLEAN.prototype._sanitize; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…