Closed danbuntu closed 8 years ago
The snippet looks fine. Can you share the rest of the code? (DB initialisation and population)
On Saturday 30 May 2015, danbuntu notifications@github.com wrote:
I'm trying to use insertOrUpdate and I'm getting the error:
Cannot read property 'toString' of null
I'm using the following code;
lib.insertOrUpdate("settings", {name: 'sound'}, { name: "sound", gameState: "0", desc: "Turns sound on and off" });
What am I doing wrong please?
— Reply to this email directly or view it on GitHub https://github.com/knadh/localStorageDB/issues/53.
the full code for the block looks lile:
var lib = new localStorageDB("carc", localStorage), existsSettings = lib.tableExists("settings"),
if (existsSettings === false) { lib.createTable("settings", ["name", "gameState", "desc"]); lib.insert("settings", {name: "gamestate", gameState: "maingame", desc: "sets the current game state"}); lib.insert("settings", {name: "slidertype", gameState: "0", desc: "sets slider type 0 = slider 1 = buttons"}); lib.insert("settings", {name: "sound", gameState: "0", desc: "Turns sound on and off"}); lib.commit(); } else { // check for sound in the setting table and add if needed lib.insertOrUpdate("settings", {name: 'sound'}, { name: "sound", gameState: "0", desc: "turns sound on and off" }); lib.commit();
}
existsSettings = lib.tableExists("settings"),
^ this statement has to terminate with a semi column, yes?
On Saturday 30 May 2015, danbuntu notifications@github.com wrote:
the full code for the block looks lile:
var lib = new localStorageDB("carc", localStorage), existsSettings = lib.tableExists("settings"),
if (existsSettings === false) { lib.createTable("settings", ["name", "gameState", "desc"]); lib.insert("settings", {name: "gamestate", gameState: "maingame", desc: "sets the current game state"}); lib.insert("settings", {name: "slidertype", gameState: "0", desc: "sets slider type 0 = slider 1 = buttons"}); lib.insert("settings", {name: "sound", gameState: "0", desc: "Turns sound on and off"}); lib.commit(); } else { // check for sound in the setting table and add if needed lib.insertOrUpdate("settings", {name: 'sound'}, { name: "sound", gameState: "0", desc: "turns sound on and off" }); lib.commit();
}
— Reply to this email directly or view it on GitHub https://github.com/knadh/localStorageDB/issues/53#issuecomment-107065540 .
sorry yes bad cut and paste on my part - that bit is correct in my code - I have a whole bunch of other tableexists calls in the function but I removed them when pasting here to simplify it
The problem must be elsewhere. I tested the following and it worked fine.
var lib = new localStorageDB("carc", localStorage),
existsSettings = lib.tableExists("settings");
if (existsSettings === false) {
lib.createTable("settings", ["name", "gameState", "desc"]);
lib.insert("settings", {name: "gamestate", gameState: "maingame", desc: "sets the current game state"});
lib.insert("settings", {name: "slidertype", gameState: "0", desc: "sets slider type 0 = slider 1 = buttons"});
lib.insert("settings", {name: "sound", gameState: "0", desc: "Turns sound on and off"});
lib.commit();
} else {
// check for sound in the setting table and add if needed
lib.insertOrUpdate("settings", {name: 'sound'}, {
name: "sound",
gameState: "0",
desc: "turns sound on and off"
});
lib.commit();
}
console.log(lib.queryAll("settings"));
hmm blast. I'll keep digging - thanks for your time
I'm trying to use insertOrUpdate and I'm getting the error:
Cannot read property 'toString' of null
I'm using the following code;
lib.insertOrUpdate("settings", {name: 'sound'}, { name: "sound", gameState: "0", desc: "Turns sound on and off" });
What am I doing wrong please?