-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Date format returned via REST API does not match model definition #1948
Comments
@property({
type: 'date',
default: () => new Date(),
})
thedate?: string; will get If you specify type: 'string' you will get the result in the format you specified above when opened the issue. |
TL;DR: I was able to reproduce the problem. The trick is to:
My conclusion is that we need to add support for The full story goes below. Lets' investigate. How does the in-memory connector work?
All is good so far. Let's switch to MySQL.
Let's try to change the MySQL column type from
|
It looks like juggler does have some sort of support for I am not sure if When I changed Todo example to define
Not what we wanted! I think it will be best to define a new type to represent values values with a date part but no time part. |
AFAICT, the conversion is done by the mysql driver, see here: https://github.com/mysqljs/mysql/blob/ad014c82b2cbaf47acae1cc39e5533d3cb6eb882/lib/protocol/packets/RowDataPacket.js#L57-L87 Fortunately, this behavior can be disabled by setting the connector (LB dataSource) option
I have verified that when I enable this option, the problem goes away. Just add the following line to your
|
I opened a new issue to keep track of implementing DATE as a new type in LoopBack - see #1966. Let's keep this issue focused on helping @chris-greenlight to find a short-term workaround using what LB4 provides right now. @chris-greenlight could you please enable |
Yes will try that and report back
…On Fri, Nov 2, 2018 at 4:52 AM Miroslav Bajtoš ***@***.***> wrote:
I opened a new issue to keep track of implementing DATE as a new type in
LoopBack - see #1966
<#1966>.
Let's keep this issue focused on helping @chris-greenlight
<https://github.com/chris-greenlight> to find a short-term workaround
using what LB4 provides right now.
@chris-greenlight <https://github.com/chris-greenlight> could you please
enable dateStrings in your datasource config and confirm that it solves
the problem?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1948 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AmwxD-7I-_d26TQD-6a9UrwivTignmU0ks5urAfggaJpZM4YDBJR>
.
|
@chris-greenlight have you had a chance to try add |
@bajtos do you know how to disable this behavior using a postgresql database? I wasn't able to find anything similiar to the "dateStrings" option in mysql for postgresql. |
@RipkensLar Our postgresql connector is using pg under the hood. I did a quick search and it looks like pg does not handle DATE values correctly - see the discussion in brianc/node-postgres#1844. I think that means you are out of luck :( Here are few more items that may be relevant: brianc/node-postgres#783, brianc/node-postgres#510 and other issues/pull-requests linked. |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Worked for me at @property({
type: 'string',
default: null,
mysql: {
dataType: 'DATE',
},
})
date_of_birth: string; In Datasource config {
name: 'db',
connector: 'mysql',
host: process.env.DB_HOSTIP ?? '127.0.0.1',
port: 3306,
user: process.env.DB_USER ?? 'root',
password: process.env.DB_PASS ?? 'password',
database: process.env.DB_NAME ?? 'db',
dateStrings: ['DATE'], // added this as suggested by @bajtos
} |
This workaround worked for me: brianc/node-postgres#1844 (comment) The solution is to override the parser for
|
Description/Steps to reproduce
Using Loopback 4. This is a simple model that uses a MySQL datasource.
The model field for the date is like this -- using string for date type, since MySQL will convert:
@property({ type: 'string', length: 100, id: false, required: true, }) thedate: string;
The create operation via REST API specified the date value like
{"thedate": "2018-01-01"}
The value stored in the database (DATE type field) is exactly that,
2018-01-01
Later a GET for the same resource formats the date like
Sun Jan 01 2018 20:00:00 GMT-0400 (Eastern Daylight Time)
Where is this conversion happening? How can I disable it?
The correct response is the same as the input:
2018-01-01
Additional information
node -e 'console.log(process.platform, process.arch, process.versions.node)'
darwin x64 10.10.0
npm ls --prod --depth 0 | grep loopback
Thank you
The text was updated successfully, but these errors were encountered: