google/lovefield

Problem selecting data

hamrio opened this issue · 4 comments

I got a problem while selecting data from IndexedDB using lovefield. Sometimes, the data was inserted and I have been checked the value exists. Here is the screenshot

image
this is the data

image
this is the result while trying open with console. as it is shown, the result is 0 which supposed to be min 1 as there is the data in it.

Has anyone experience the same problem?

Thanks

Are you attaching a then() handler to the returned Promise? Looking at the snippet above, I don't see the results. There should be an empty array if no results where found. Instead the snippets just logs the returned Promise itself.

For both of exec() and then() is return promise. I don't think that's the problem.

I've found where the problem lies. The condition as screenshot above is less than actual, for actual condition that I used, I used op and.

this is the code

var t = db.getSchema().table('historyCurrency')

  db.select().
      from(t).
      where(lf.op.and(t.currency.eq("MYR"),t.day_hour.eq("18"))).
      exec().then(function(data){})

The problem lies with day_hour. I create day_hour at schema as Integer, but sometimes it can be read as integer but more likely as String. when I convert it to String (like code above) the problem is gone.

Is there something I missing here?

If you are mixing the day_hour field with sometimes strings, and sometimes numbers, yes this is definitely a problem. You need to be consistent with whatever you declared that field in your schema.

If you choose lf.Type.STRING, you always have to store a string, and the comparisons done by Lovefield will use alphabetical order (which is probably not what you want). If you chose lf.Type.NUMBER, or lf.Type.INTEGER, you always have to store as a Javascript number, and the comparisons done by Lovefield will be numerical (probably what you want).

Since you chose INTEGER already, you need to fix how your database is populated and ensure that you do not enter String values where Number values are expected. This should fix any weirdness you are observing.

I populate my data from json. I thought it will be automatically change to integer as I input a number. Better I cast the input first then.

Thank you