The Wayback Machine - https://web.archive.org/web/20210124105414/https://github.com/sql-js/sql.js/issues/334
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

Feature Request: Handling JS Date variables #334

Open
pupudu opened this issue Jan 22, 2020 · 1 comment · May be fixed by #335
Open

Feature Request: Handling JS Date variables #334

pupudu opened this issue Jan 22, 2020 · 1 comment · May be fixed by #335
Labels

Comments

@pupudu
Copy link

@pupudu pupudu commented Jan 22, 2020

First of all, thanks for creating/maintaining this amazing library. I'll cut into my request.

Background

I am using sql.js with typeorm to do integration testing rather than spinning up a mysql service for that.

Issue

I noted that if I use Javascript Date objects in the where conditions, it works in production, but fails in tests, because sql.js doesn't convert the dates similar to how node-mysql driver does that.

Expectation

I would love it if sql.js would convert the dates correctly.
For example, take the following example:

const updatedAt = new Date(/*Some date string goes here*/);

// Assume db is setup correctly as explained in ReadMe
db.run("SELECT * FROM test_table WHERE example_column = ?", [updatedAt]);

Now, this fails because sql.js would call updatedAt.toString(). But AFAIK, in node-mysql they call updatedAt.toISOString() (or some valid date string) internally.

Notes

  1. Code works with sql.js when we do updatedAt.toISOString() explicitly
  2. The error that's being thrown at the moment is:
QueryFailedError: Wrong API use : tried to bind a value of an unknown type (Fri Jan 11 2019 01:01:01 GMT+1100 (Australian Eastern Daylight Time)).

    at new QueryFailedError (/Users/pubudu/Projects/typeorm-test/src/error/QueryFailedError.ts:9:9)
    at SqljsQueryRunner.<anonymous> (/Users/pubudu/Projects/typeorm-test/src/driver/sqljs/SqljsQueryRunner.ts:79:22)
@lovasoa
Copy link
Member

@lovasoa lovasoa commented Jan 22, 2020

This would be a useful feature. Pull requests are welcome!

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

Successfully merging a pull request may close this issue.

2 participants