knadh / localStorageDB

A simple database layer for localStorage and sessionStorage for creating structured data in the form of databases and tables
http://nadh.in/code/localstoragedb
814 stars 128 forks source link

Bug while inserting/updating null values into db #36

Closed orangecoding closed 10 years ago

orangecoding commented 10 years ago

Hi, we found an issue updating rows with null values. While an insert will save null values (examle: {a: "hello", b: null}), an update will remove the field with null as value (example: {a: "hello"}, field b does not exist any more). After investigating the code we found out that the function validFields(), which is called during update, filters field with undefined or null values.

While we are questioning if maybe it should be possible to store null values in the database it at least seems odd that null values are inserted but removed with updates.

Suggestion: Change the line (in function validFields) if ((data[field] !== null && data[field] !== undefined)) { to if (data[field] !== undefined) {

knadh commented 10 years ago

https://github.com/knadh/localStorageDB/commit/63a17494ebe3e22f442f43fc25d432d52098afb1 fixes this.