Skip to content

field.length undefined in typeCast function #519

Closed
@sgerace

Description

@sgerace

I'm trying to implement a typeCast function on my conenction pool to convert TINYINT(1) to boolean, as provided in the documentation:

var sqlpool = mysql.createPool({
  host: [...],
  user: [...],
  password: [...],
  timezone: 'Z',
  typeCast: function (field, next) {
    if (field.type == 'TINY' && field.length == 1) {
      return (field.string() == '1'); // 1 = true, 0 = false
    }
    return next();
  }
})

However, I'm always getting undefined for field.length (regardless of field type) so this is currently failing. Is there something else I need to enable to get the field length, or is something else going on here?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions