WebReflection / dblite

sqlite for node.js without gyp problems
MIT License
209 stars 34 forks source link

Extra Bonus (ERROR): JSON Serialization With fields:Array|Object #11

Closed korgon closed 10 years ago

korgon commented 10 years ago

This is not working for me (v0.8.22). I tried using this functionality and it failed with an error. So I decided to just take the example code listed here and run it, the same error occurred. This is the code I ran:

var dblite = require('dblite'), db = dblite(':memory:');

db.query('CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, value TEXT)'); db.query('INSERT INTO test VALUES(null, ?)', ['some text']); db.query('SELECT * FROM test');

db.query('INSERT INTO test VALUES(?, ?)', [ 123, {name: 'dblite', rate: 'awesome'} // value serialized ]);

// use the fields to parse back the object db.query('SELECT * FROM test WHERE id = ?', [123], { id: Number, value: JSON.parse // value unserialized }, function (rows) { var record = rows[0]; console.log(record.id); // 123 console.log(record.value.name); // "dblite" console.log(record.value.rate); // "awesome"" });

Produced this error:

/home/node/webs/node_modules/dblite/build/dblite.node.js:692 "'" + what.replace(SINGLE_QUOTES, SINGLE_QUOTES_DOUBLED) + "'" ^ TypeError: Object # has no method 'replace' at escape (/home/node/webs/node_modules/dblite/build/dblite.node.js:692:20) at replaceQuestions (/home/node/webs/node_modules/dblite/build/dblite.node.js:644:10) at String.replace (native) at replaceString (/home/node/webs/node_modules/dblite/build/dblite.node.js:626:21) at EventEmitter.self.query (/home/node/webs/node_modules/dblite/build/dblite.node.js:481:17) at next (/home/node/webs/node_modules/dblite/build/dblite.node.js:208:18) at Socket. (/home/node/webs/node_modules/dblite/build/dblite.node.js:291:9) at Socket.EventEmitter.emit (events.js:96:17) at Pipe.onread (net.js:397:14)

WebReflection commented 10 years ago

you are right .. damn it me, I should have put a test for that. Thanks for the report

WebReflection commented 10 years ago

test in place, behavior as described. let me know if latest is OK and eventually feel free to close this, thanks :-)

korgon commented 10 years ago

Thanks for the quick fix and the awesome module.