MCPcopy
hub / github.com/sequelize/sequelize / BOOLEAN

Class BOOLEAN

lib/data-types.js:379–407  ·  view source on GitHub ↗

* A boolean / tinyint column, depending on dialect

Source from the content-addressed store, hash-verified

377 * A boolean / tinyint column, depending on dialect
378 */
379class 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
410BOOLEAN.parse = BOOLEAN.prototype._sanitize;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…