{"action":"reopened","issue":{"url":"https://api.github.com/repos/robconery/massive-js/issues/60","labels_url":"https://api.github.com/repos/robconery/massive-js/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/robconery/massive-js/issues/60/comments","events_url":"https://api.github.com/repos/robconery/massive-js/issues/60/events","html_url":"https://github.com/robconery/massive-js/issues/60","id":73197101,"number":60,"title":"Problem with table insert function","user":{"login":"stephensong","id":108766,"avatar_url":"https://avatars.githubusercontent.com/u/108766?v=3","gravatar_id":"","url":"https://api.github.com/users/stephensong","html_url":"https://github.com/stephensong","followers_url":"https://api.github.com/users/stephensong/followers","following_url":"https://api.github.com/users/stephensong/following{/other_user}","gists_url":"https://api.github.com/users/stephensong/gists{/gist_id}","starred_url":"https://api.github.com/users/stephensong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephensong/subscriptions","organizations_url":"https://api.github.com/users/stephensong/orgs","repos_url":"https://api.github.com/users/stephensong/repos","events_url":"https://api.github.com/users/stephensong/events{/privacy}","received_events_url":"https://api.github.com/users/stephensong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-05-05T03:52:08Z","updated_at":"2015-05-13T06:57:04Z","closed_at":null,"body":"Encountered some problems with massive's  table.insert function.  \r\n\r\nIt works fine if I call it thusly:\r\n\r\n    tbl.insert(solnRows); \r\n\r\n(solnRows contains 225 rows, all 225 are inserted ok.) But if I call it like this:\r\n\r\n    solnRows.forEach(function (r) { tbl.insert(r); });\r\n\r\nit only ever inserts exactly 10 rows, whilst remaining disturbingly silent about what might have happened with the other 215.\r\n\r\nTrying to get to the bottom of the issue, I constructed my own  bastardized version of the massive\r\ninsert function:\r\n\r\n    let insert_rows = function(tblName, data, next) {\r\n        if(!data) throw \"insert should be called with data\";\r\n        if (!_.isArray(data)) { data = [data]; }\r\n\r\n        var delimitedColumnNames = _.map(_.keys(data[0]), function(key){return util.format('\"%s\"', key);});\r\n        var sql = util.format(\"INSERT INTO %s (%s) VALUES\\n\", tblName, delimitedColumnNames.join(\", \"));\r\n        var rows = _.map(data, function(r) { return \"(\" + _.map(_.values(r),formatValue).join(\", \") + \")\"; });\r\n        sql += rows.join(\",\\n\");\r\n        sql += \" RETURNING *\";\r\n        //console.log(sql);\r\n        pg.connect(url, function (err,client, done) {\r\n            client.query(sql, null, function (err, res) {\r\n                done();  // return client to pool\r\n                if (next) next(err,res);\r\n            });\r\n        });\r\n    };\r\n\r\nwhere formatValue basically calls pg's prepareValue, and then quotes everything but numbers, booleans and nulls.\r\n\r\nFor some reason, the above function can be called either way, and always inserts the full 225 rows.\r\nSo, as yet I've still not been able to come up with any explanation at to why the native massive insert should fail (silently !!! eeek....) the way it does.   Anybody got a clue?\r\n\r\nThanks,\r\n\r\ngary\r\n\r\n\r\n\r\n"}}