Skip to content

feat: Typecast Javascript Date objects to ISOStrings #335

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

Closed
wants to merge 1 commit into from

Conversation

pupudu
Copy link

@pupudu pupudu commented Jan 23, 2020

Without this change, using JS Date objects in bind values will make the library throw. By using the ISOString version we align with node-mysql on their typecasting behaviour for Date objects

Fixes #334

Without this change, using JS Date objects in bind values will make the library throw. By using the ISOString version we align with node-mysql on their typecasting behaviout for Date objects
@lovasoa
Copy link
Member

lovasoa commented Jan 23, 2020

Great, thank you very much for your contribution! Can you please add one or more tests for the feature?

@pupudu
Copy link
Author

pupudu commented Jan 23, 2020

Glad you like it. Will add the test soon

Copy link
Member

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you meant to change was the Statement::bind function.

@@ -495,6 +495,8 @@ class Database
blobptr = allocate result, 'i8', ALLOC_NORMAL
sqlite3_result_blob(cx, blobptr,result.length, -1)
_free blobptr
else if result instanceof Date
sqlite3_result_text(cx, result.toISOString(), -1, -1)
Copy link
Member

@lovasoa lovasoa Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is what you wanted ?
This change allows user-defined functions to return a Date. This is great, but wasn't #334 about adding Date support to prepared statement parameters ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tips @lovasoa
Looks like I was too quick. I changed the build files and my test passed. Didn't realize there were two similar blocks of code.
Now that you have showed me the direction, let me take my time to fix the issues, add tests, add docs and polish the PR

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

Successfully merging this pull request may close these issues.

Feature Request: Handling JS Date variables
2 participants