Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldInfo.type is string and not Types #54

Closed
leon opened this issue May 17, 2019 · 1 comment
Closed

FieldInfo.type is string and not Types #54

leon opened this issue May 17, 2019 · 1 comment

Comments

@leon
Copy link

leon commented May 17, 2019

using Typescript.

I want to do some type casting when returning data.
So I use the typeCast function that is available on the createPool options

My problem is that the parameter FieldInfo.type is typed as a mariadb.Types which is a enum with values such as TINY = 0x01, // aka TINYINT, 1 byte

But the FieldInfo.type is of type string. Which causes typescript to complain.

Example

const pool = createPool({
  host: 'localhost',
  user: 'root',
  password: '',
  database: 'testdb',
  connectionLimit: 5,
  typeCast: (field: FieldInfo, useDefaultTypeCasting) => {
    if (field.type === Types.BIT || field.type === Types.TINY) {
      // we never get here because Types.BIT is a number and field.type is a string 'BIT'
      return field.int() === 1;
    }
    return useDefaultTypeCasting();
  }
});

How to fix.

in typescript for FieldInfo.type introduce new enum that is string based.

@rusher
Copy link
Collaborator

rusher commented May 20, 2019

( https://jira.mariadb.org/browse/CONJS-74 )
corrected in 4b7bbf5

Will be in next release 2.0.6

@rusher rusher closed this as completed May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants