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

dateStrings not implemented. #99

Closed
JemiloII opened this issue Apr 30, 2014 · 8 comments
Closed

dateStrings not implemented. #99

JemiloII opened this issue Apr 30, 2014 · 8 comments

Comments

@JemiloII
Copy link

mysql.createConnection({
    host        : 'localhost',
    user        : 'root',
    password    : 'pass',
    database    : 'dbname',
    dateStrings : 'DATE' //this does nothing
});

I tried the other dateStrings commands and they didn't work. So I just installed the original and the dateStrings method works just fine.

@sidorares
Copy link
Owner

Yes, it's currently ignored. I'll add support for this option in next release

@JemiloII
Copy link
Author

thanks!!

@sidorares
Copy link
Owner

published as v0.12.1

Note that it's a boolean option ( though if you set it to 'DATE' string it's still treated as truthy )

@JemiloII
Copy link
Author

Your the bomb! I'll keep on mind that it's a boolean and just set it to true :)

Andrey Sidorov [email protected] wrote:

published as v0.12.1

Note that it's a boolean option ( though if you set it to 'DATE' string it's still treated as truthy )


Reply to this email directly or view it on GitHub.

@kbsanders
Copy link

I really only want DATE fields to be treated as strings but not DATETIME fields. I see that mysqljs/mysql now supports an array of types for dateStrings in addition to a boolean value. Will we see the same option added to mysql2?

In their Connection Options:

dateStrings: Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather than inflated into JavaScript Date objects. Can be true/false or an array of type names to keep as strings. (Default: false)

@sidorares
Copy link
Owner

wow, I missed that this was added to mysqljs/mysql

it's relatively simple change - would you like to try adding it @kbsanders ? Let me know if you need any help navigating the code

@kbsanders
Copy link

@sidorares Thanks for the quick reply. If I find time in the next few days I will submit a PR.

In the meantime, I'm using this workaround of providing a typeCast in the options:

// NOTE: only works for .query() calls and not .execute() calls.
typeCast: function ( field, next ) {

    if ( field.type === "DATE" ) {
        return field.string();
    }
    
    return next();
}

Along the way I discovered that typeCast was only being called for .query() and not .execute() so I had to refactor my code to use .query(). I don't know if this is a limitation of the way prepared statements work or not, but I guess that is a topic for a new issue.

@sidorares
Copy link
Owner

I don't know if this is a limitation of the way prepared statements work or not, but I guess that is a topic for a new issue.

see discussion in #649 and #717

B4nan added a commit to B4nan/node-mysql2 that referenced this issue Sep 12, 2020
This aligns the `dateStrings` with mysqljs, allowing to set `dateStrings: ['DATE']` to return
the DATE type as string, but keeping other datetime types processed to Date.

Related: sidorares#99
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

3 participants