Created
October 11, 2014 08:01
-
-
Save you21979/d6028d6c57450c861456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createBulkInsertBuilder = function(tbl, keys, count){ | |
var f = function(keys, count){ | |
var w = []; | |
for(var i = 0; i<count; ++i){ | |
w.push('(' + keys.map(function(v){ return '?'}).join(',') + ')') | |
} | |
return w; | |
} | |
var q = [ | |
'INSERT INTO', | |
tbl, | |
'(' + keys.join(',') + ')', | |
'VALUES', | |
f(keys, count).join(',') | |
]; | |
return q.join(' '); | |
} | |
var createBulkInsert = function(tbl, keys, datalist){ | |
return { | |
query:createBulkInsertBuilder(tbl, keys, datalist.length), | |
datalist:datalist, | |
} | |
} | |
var l = [[100,'aaa'],[101,'bbb'],[102,'ccc']] | |
console.log(createBulkInsert('hoge', ['id','aaa'], l)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment