google / lovefield

Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.
https://google.github.io/lovefield/
Apache License 2.0
6.82k stars 367 forks source link

indexed nullable DATE_TIME field causes error on .insert() unless specified #273

Open fezzzza opened 3 years ago

fezzzza commented 3 years ago

I have been using lovefield for a while, but now I am starting to use DATE_TIME columns. I discover that if they are .addIndex()-ed they must be specified explicitly on .insert() - even if made .addNullable(), as an uncaught error occurs. However if the column is not indexed, the error does not occur but they are incorrectly assigned the default value of null, instead of Date(0).

Repro: https://plnkr.co/edit/sZ7gGCDpXWrOTpKC

As you can see from test 2, treating a STRING in the same way results in more expected behaviour.

I have tested further without .addNullable() and my tests mostly result in error 202:

Constraint error: (202) Attempted to insert NULL value to non-nullable field deals.[FIELDNAME]

Further testing shows a 202 error is generated for whichever field is not specified, whether STRING, DATE_TIME, INTEGER, NUMBER or BOOLEAN.

However, according to documentation the default value for a DATE_TIME field is Date(0). I presume this to be new Date (0) and not a string representation of the current date/time, and this is borne out by inspecting lf.type .

However observed behaviour suggests that the default values for STRING, DATE_TIME, INTEGER, NUMBER and BOOLEAN are not implemented, because when added with .addNullable() they come out as undefined, and not null.

So I did another test: https://plnkr.co/edit/4351TPYa7BlSVn7d?preview

...and it appears that the defaults specified in lf.type are not applied at all.

Perhaps that is the root of this issue?

freshp86 commented 3 years ago

Thanks for filing. Will take a look and respond on this thread with any updates.