loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Problems with dates on query

Open carloscarcamo opened this issue 9 years ago • 3 comments

Hi, I need some help with an issue I'm experimenting with loopback, I'm having a problem with a query that looks like this:

let promise = new Promise((resolve, reject) => {
  RhEmpleados.findOne({
    where: {
      identidad: params.dui.trim(),
      fechaNacimiento: params.birthDate.trim(),
      accesoApp: true,
      idEstatus: {neq: 'E'}
    }
  }, (err, RhModel) => {
    if (err) return reject(err);
    resolve(RhModel);
  });
});

I was debugging and I noticed something in the query that loopback does, in the where clause I always get:

WHERE ... AND "fecha_nacimiento"= '1979-11-21T00:00:00.000Z'::TIMESTAMP WITH TIME ZONE AND ...

With '1979-11-21T00:00:00.000Z'::TIMESTAMP WITH the query does not return any row, if I change the query to "fecha_nacimiento" = '1979-11-21' the query works like a charm.

In the model definition I have this:

...
"fechaNacimiento": {
  "type": "Date",
  "required": false,
  "length": null,
  "precision": null,
  "scale": null,
  "postgresql": {
    "columnName": "fecha_nacimiento",
    "dataType": "date",
    "dataLength": null,
    "dataPrecision": null,
    "dataScale": null,
     "nullable": "YES"
   }
}
...

I'm having this issue on Postgres v9.1, I tested on Postgres v9.3 and it works.

How can I prevent loopback adds time zone and TIMESTAMP WITH TIME ZONE to my query?

I'm using loopback v2.22.0 and loopback-datasource-juggler v.2.39.0

I'll appreciate your help, thanks in advance.

carloscarcamo avatar Jul 07 '17 17:07 carloscarcamo

@carloscarcamo -- a couple ideas:

  1. if you're having this issue on Postgres v9.1 and it works on Postgres v9.3, any reason why not move to v9.3?
  2. if v9.3 is not an option, what if you modify the following line in postgres connector not to add TIMESTAMP WITH TIME ZONE ?
    https://github.com/strongloop/loopback-connector-postgresql/blob/master/lib/postgresql.js#L523

Setogit avatar Jul 10 '17 18:07 Setogit

@Setogit thanks for your suggestions, I chose the second option, now I don't have problems with dates :)

carloscarcamo avatar Jul 14 '17 13:07 carloscarcamo

@carloscarcamo happy to hear that. closing.

Setogit avatar Jul 21 '17 20:07 Setogit