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

Custom data type handlers #1170

Closed
anton-johansson opened this issue Jan 14, 2021 · 2 comments · Fixed by #1356
Closed

Custom data type handlers #1170

anton-johansson opened this issue Jan 14, 2021 · 2 comments · Fixed by #1356

Comments

@anton-johansson
Copy link

I'm loading DATE, DATETIME and DATETIMEOFFSET(3) from my SQL server database. I've only tested DATETIME with node-mssql so far, but it looks like it's parsed into a native JavaScript Date, which makes sense. However, I would want to change this so that...:

  • DATE (sql.Date) into js-jodas LocalDate
  • DATETIME (sql.DateTime) into js-joda's LocalDateTime
  • DATETIMEOFFSET(x) (sql.DateTimeOffset [scale]) into js-joda's ZonedDateTime

Is there a way to register custom handlers for these types?

@dhensby
Copy link
Collaborator

dhensby commented Jan 14, 2021

At the moment there's no way to customise the parsed type.

This would be a nice feature to add (custom typing or type resolution); the basis of it is there as we run the rows through "value correction"

const valueCorrection = function (value, metadata) {
if ((metadata.type === tds.TYPES.UDT) && (value != null)) {
if (UDT[metadata.udtInfo.typeName]) {
return UDT[metadata.udtInfo.typeName](value)
} else {
return value
}
} else {
return value
}
}

But this isn't extensible at the moment.

@anton-johansson
Copy link
Author

@dhensby Thanks for the quick response. Glad to hear it's prepared in a good way!

I would happily attempt working on a PR for this, if you'd be willing to guide me a bit. How would you want this to be configured? How would one register value correction handlers for a certain type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants