Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用NodeJS批量更新mysql_Javascript_Mysql_Sql_Node.js - Fatal编程技术网

Javascript 使用NodeJS批量更新mysql

Javascript 使用NodeJS批量更新mysql,javascript,mysql,sql,node.js,Javascript,Mysql,Sql,Node.js,编辑:我正在使用mysql版本:8.0.20和nodejs 我试图用nodejs“批量更新”mysql服务器上的信息 db.query("UPDATE coinDetail SET current_price = ?, market_cap_rank = ?, price_change_percentage_1h_in_currency = ?, price_change_percentage_24h_in_currency = ?, price_change_percentage_7

编辑:我正在使用mysql版本:8.0.20和nodejs

我试图用nodejs“批量更新”mysql服务器上的信息

db.query("UPDATE coinDetail SET current_price = ?, market_cap_rank = ?, price_change_percentage_1h_in_currency = ?, price_change_percentage_24h_in_currency = ?, price_change_percentage_7d_in_currency = ?, price_change_percentage_30d_in_currency = ?, price_change_percentage_200d_in_currency = ?, price_change_percentage_1y_in_currency = ? WHERE id = ?",
    [testvalue], function (error, results, fields) {
        if(error) {
            console.log(error.message);
        }
    })
Testvalue
由100个
[]
值组成

Testvalue
的结构如下:

[ [ '$57453',
        1,
        -0.3420308363845882,
        5.572915018205854,
        12.233200940728546,
        -2.318933937220493,
        397.72609563393615,
        567.2380432044025,
        'bitcoin' ],
      [ '$2837.96',
        2,
        0.016409340109730643,
        2.1106445293246816,
        20.03746531858046,
        48.132112696446534,
        632.8398908252254,
        1280.6277298518,
        'ethereum' ],
      [ '$617.86',
        3,
        0.09529522096501872,
        -0.037445793001886205,
        17.06787284916119,
        104.0862961351894,
        1914.1435778621246,
        3538.5727910209353,
        'binancecoin' ],
      [ '$1.55',
        4,
        0.5061299537245372,
        0.8487206928960775,
        33.103999419202964,
        170.49836716961806,
        506.29510956451907,
        628.3743714018339,
        'ripple' ] ]
它不会更新并返回此错误消息:

  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage:
   'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'(\'$2845.46\', 2, 0.045413119974277404, 2.306167497386996, 20.35445317628596, 48.5\' at line 1',
  sqlState: '42000',
  index: 0,
  sql:
   'UPDATE coinDetail SET current_price = (\'$57716\', 1, -0.2766921515785762, 6.098656371674484, 12.746293335764888, -1.8723690017490084, 400.0015317111427, 570.2884308149984, \'bitcoin\'), (\'$2845.46\', 2, 0.045413119974277404, 2.306167497386996, 20.35445317628596, 48.523291241715, 634.775131180537, 1284.2736101210394, \'ethereum\'), (\'$619.58\', 3, -0.1026730888793722, 0.3621019596638365, 17.393082538523714, 104.65323939087486, 1919.7387850812056, 3548.680595137403, \'binancecoin\'), (\'$1.56\', 4, 0.2631104262429765, 0.7741046873839751, 33.48576103475, 171.27419580064424, 508.0340520571233, 630.4634549602749, \'ripple\'), (\'$1\', 5, 0.16995639335390175, 0.01996318106358919, -0.1680202348484999, -0.020140611552169046, 0.06200611292377157, 0.030763601560494607, \'tether\'), (\'$0.3579\', 6, 0.5589618230067042, 13.894487576577832, 43.58521027081249, 558.1266699844505, 13255.142925532036, 14554.165859193548, \'dogecoin\'), (\'$1.33\', 7, -0.17850685500985985, -1.0855257334146333, 15.33239209871934, 11.891961646202247, 1114.9761517683173, 2678.6159651340035, \'cardano\'), (\'$36.27\', 8, -0.006623587070551593, 1.4123692063082849, 12.029486810924658, -1.6695963984110422, 740.3649782714295, NULL, \'polkadot\'), (\'$39.8\', 9, -0.5132245853666173, -2.75556773024372, 20.827648597503536, 41.93320580577528, 1053.685716914155, NULL, \'uniswap\'), (\'$994.36\', 10, -0.013886879176964746, 7.33063801349993, 18.888849122294207, 84.08312312362163, 314.4876751150548, 299.34841772883084, \'bitcoin-cash\'), (\'$269.09\', 11, -0.1755790785076061, 2.2044764849790353, 11.80301310216353, 36.93790306342434, 431.43807991669314, 482.54312548063683, \'litecoin\'), (\'$38.08\', 12, -0.0009238603460533265, 0.0692322429791508, 8.650380532274346, 30.452495665950714, 231.90633705521734, 928.6410316714716, \'chainlink\'), (\'$0.999954\', 13, -0.11279977084429132, 0.005765212353196657, -0.12275183680686896, 0.09233351735183044, -0.029941063114935836, 0.1345098253346611, \'usd-coin\'), (\'$0.199387\', 14, 0.18585752981946224, 1.400833477043686, -2.8492195871822528, 126.76054943485029, 1648.2984947234534, 4306.37963084993, \'vechain\'), (\'$0.519975\', 15, 0.14362214397151868, 0.33532353155740463, 15.005279651342235, 27.696111956701802, 570.2340967015189, 667.0965541034418, \'stellar\'), (\'$43.44\', 16, 1.2773662058955155, 0.06716002518068384, 17.20176104550362, 122.93769197331544, 1581.504857209381, 6168.026513994873, \'solana\'), (\'$11.41\', 17, 0.2011744478093339, 3.066854231592038, 14.392006975817859, -6.736677662174206, 1454.5794988382568, 9547.414396497565, \'theta-token\'), (\'$163.61\', 18, -0.5602632791449774, 5.100415030491226, 17.435158357688316, -13.695681556139586, NULL, NULL, \'filecoin\'), (\'$57564\', 19, -0.24096506537476778, 5.666202300760661, 12.654485816597441, -2.1383580802362023, 398.7389110831461, 568.2034906490744, \'wrapped-bitcoin\'), (\'$0.130199\', 20, 0.024697670911813838, 4.033100446621522, 19.05435822641194, 41.66913601798783, 380.460752805762, 753.9427586630561, \'tron\'), (\'$29.54\', 21, -0.14596654692615418, 42.524775097975414, 77.96098604155728, 74.19820982491096, 382.2623864985581, 456.23901700353986, \'okb\'), (\'$421.63\', 22, -0.06436592074606837, 3.0444638381379483, 18.959704341829806, 70.91756724539961, 223.62708693946107, 579.2142892443229, \'monero\'), (\'$0.999787\', 23, -0.3539051853470827, 0.0029549323194855474, -0.2258807635519472, 0.054463844632277165, 0.012584613263016771, 0.12991778187742334, \'binance-usd\'), (\'$95.99\', 24, 0.1727922049662666, 2.7321336435002164, 11.542058162283361, 89.28426268947467, 432.08354778648885, 982.5895781524613, \'neo\'), (\'$40.43\', 25, 0.8242065565558704, -7.082478382626721, 49.739835553141795, 122.13986141699695, 3545.161568342976, NULL, \'pancakeswap-token\'), (\'$16.51\', 26, -0.047534654095087885, -1.2168026486672043, 17.633448747406554, -11.435176719947812, 4973.986682270988, 8551.773946962172, \'terra-luna\'), (\'$6.4\', 27, -0.26212048300024504, 3.548538377949975, 14.901727410581417, 33.566927545833906, 142.08583214984657, 126.76595075100411, \'eos\'), (\'$2.44\', 28, 0.3025358353372535, -0.1511922836691293, 10.0576034862878, -40.507203813558355, 421.4877081405621, 3467.3301654701218, \'klay-token\'), (\'$317.32\', 29, 0.014773326405343278, 6.7739012068524, 26.850270532742787, 46.4352602819229, 86.46138736932566, 53.10836641485337, \'bitcoin-cash-sv\'), (\'$467.31\', 30, 1.2186035551424437, 7.470925700905487, 35.96660691021585, 22.605604720306705, 809.8813168185917, NULL, \'aave\'), (\'$2.09\', 31, -0.3113886732706193, 0.9529101647299612, 13.462141405897151, 36.89579701998489, 619.5374869892121, 1085.7102192222992, \'iota\'), (\'$22.69\', 32, -0.40914841879935593, -1.0415763110743008, 10.716330020687298, 19.088791257731334, 279.152929697307, 731.7235251441614, \'cosmos\'), (\'$39.67\', 33, 1.659009928805134, 12.062557991921347, 21.03251025173607, 182.30948920934264, 626.9623723728768, 516.4231530382203, \'ethereum-classic\'), (\'$0.195638\', 34, -0.12488948939155405, 1.5016797181326287, 11.329359430540329, -9.147427782920186, 26.582375631313365, 237.75586365886193, \'crypto-com-chain\'), (\'$0.00735211\', 35, -0.22512099115631493, 4.1486351891721425, 0.062491708879117036, 44.166224310370936, 2001.0671881806868, 2763.266567913546, \'bittorrent-2\'), (\'$54.93\', 36, -0.01326742179813206, 1.807984282518748, 15.748175984158713, 37.71212097781359, 1406.099606059696, 1680.3041763568367, \'ftx-token\'), (\'$0.800887\', 37, 0.710517390458153, -9.71416247113691, 108.79842315551073, 122.82427886706803, 4382.9520457290855, 5088.703945875686, \'matic-network\'), (\'$25.55\', 38, -0.7925097051021417, 10.46393834305037, 37.71834736598096, 63.43438509829361, 439.78541467954494, 510.1077820239583, \'huobi-token\'), (\'$0.02196122\', 39, -0.1206357080869783, 0.09297751013712754, 0.20070726378081769, 0.6000285664919112, 3.6016845581523196, 4.5460180892158615, \'compound-usd-coin\'), (\'$33.83\', 40, 1.162306384448545, 11.03266116168885, 43.75506031596383, 18.097530645853524, 666.2752558041045, NULL, \'avalanche-2\'), (\'$5.59\', 41, 0.22829308955961142, 3.2196570554999506, 16.041610347036507, 16.53773714750483, 138.64267934691438, 103.7387858617913, \'tezos\'), (\'$56.81\', 42, -0.07952686164479572, 1.8795367764334805, 19.981088334571712, 48.10123040795216, 633.4454217591549, 1279.1186584670882, \'compound-ether\'), (\'$4626.25\', 43, 1.5329418877404835, 8.985990895476597, 13.778033568287427, 118.50139633732624, 682.1482452203691, 1279.439433844729, \'maker\'), (\'$1.37\', 44, -0.2642211131233025, -4.057082133905676, 17.366774086675406, 0.5339102149515061, 296.2896681591828, 546.9599740714216, \'algorand\'), (\'$780.86\', 45, 0.6653505418710755, 16.9840135481407, 25.533214410032766, 96.08390984271861, 565.6611635804004, NULL, \'compound-governance-token\'), (\'$0.997338\', 46, -0.1800123518846229, -0.4304015970014756, -0.34045943409780727, -0.1784265553779978, -1.1317069981158956, -1.812843452154278, \'dai\'), (\'$408.6\', 47, -0.6722215798559669, 5.7738754076733985, 22.460296065926272, -17.79757995944082, 1172.570358552149, 7903.609058152618, \'kusama\'), (\'$0.02142176\', 48, -0.11678855756700357, 0.06839187176084088, -0.20152460488115517, 0.5921479637748314, 2.444794209281232, 3.2116206822087676, \'cdai\'), (\'$15.14\', 49, -0.1228110628287917, 0.6128627904176626, 15.707473802714805, 90.64902534453095, 2491.3910796343507, 13418.627851994677, \'thorchain\'), (\'$314.66\', 50, 0.013100241589207104, 1.6572335395287672, 19.856898992473834, 41.65518707090791, 338.6150522524714, 289.8341034245631, \'dash\'), (\'$180.27\', 51, -0.03774915695782437, 0.3442809485018537, 11.727311278462702, 28.61997444743395, 2155.308820451665, NULL, \'elrond-erd-2\'), (\'$0.341842\', 52, -1.83628573144924, -0.7012713836473469, 18.74913200677904, -10.431189787561017, 180.7556693810882, 742.1985222124842, \'nem\'), (\'$0.558704\', 53, 1.6127258579770578, -1.817251819242915, 30.70238763365436, 11.637393040486547, 4914.356985283939, 7641.487694377177, \'chiliz\'), (\'$0.0160901\', 54, -0.8702074310149466, 3.3488423507810854, 32.54287912971548, -4.515406043659077, 3023.0731915368874, 4429.5832279923015, \'holotoken\'), (\'$249.33\', 55, -0.06253455368731711, 4.584979543280797, 13.540392567905988, 58.44518354202138, 239.54727818972134, 455.87641788840017, \'zcash\'), (\'$17.88\', 56, 0.08976607312103813, -0.07718765461816145, 19.870294725410385, 1.332059491889294, 284.59366440039184, 2251.3506016283236, \'havven\'), (\'$204.31\', 57, -0.1427913773521275, 0.3783956943335357, 10.533696450411172, 13.702409390998865, 1567.501538509236, 1442.5488885997722, \'decred\'), (\'$2.73\', 58, 0.4847677803252795, 1.9385753960617764, 22.2573646874829, 7.4135710738861285, 1538.6235226463937, 1905.0681335483819, \'enjincoin\'), (\'$0.206706\', 59, 0.5576148808468434, 3.160718748779846, 30.181835761754716, 16.414775416690077, 918.6135974587501, 3726.4671231589646, \'zilliqa\'), (\'$0.293084\', 60, 0.8575784818753062, -0.6220652506814066, 8.844672759673369, -20.49574035377061, 753.2622870886579, 729.619958956365, \'hedera-hashgraph\'), (\'$6.27\', 61, 1.7476630081383546, 9.340376091729519, -7.906815306983966, 30.27602185120189, 363.33735725125047, 5462.231169002883, \'celsius-degree-token\'), (\'$2.43\', 62, -0.29428979871400335, 5.305393035743892, 6.2654742411297235, 19.787967157782223, 104.34439158458848, 130.36662860043427, \'leo-token\'), (\'$0.161019\', 63, -0.7691589302104842, 25.08955953041624, 29.00603970740522, 117.28903755950275, 535.5387651706716, 963.311249317598, \'digibyte\'), (\'$14.58\', 64, 0.11395314163113938, 1.9643597814006621, 23.354902169129076, -0.4666858185500531, 1813.5216204617748, NULL, \'sushi\'), (\'$22.39\', 65, 0.5254102674202016, 2.108254638304809, 51.84458251354891, 87.34530362163085, 808.963867819315, 2028.3611711584495, \'waves\'), (\'$2.11\', 66, -0.040768423388125856, -0.2966929468988792, 7.426426869405722, 73.64494514153895, 1169.5360628664669, 1951.5412722377064, \'blockstack\'), (\'$3.72\', 67, 0.6031315893250373, 0.9233197850103488, 8.731228674407499, 34.95366921004057, 2786.496865636743, 3330.065956599455, \'nexo\'), (\'$0.057218\', 68, 0.26188860169035455, 6.505261125033769, 14.661219209871144, 98.64877381612925, 870.9582296785558, NULL, \'amp-token\'), (\'$1.65\', 69, -0.05695060068932193, 7.485443943354529, 18.693300036957787, -3.7475261746118695, NULL, NULL, \'the-graph\'), (\'$5.45\', 70, 0.4077283208255781, 1.8135868488269486, 18.271666562984695, -9.159080362842966, NULL, NULL, \'near\'), (\'$0.999646\', 71, -0.24040366335140598, 0.3843805193031856, -0.2436434768976605, 0.06081407009969681, 0.1118739717163893, NULL, \'terrausd\'), (\'$1.44\', 72, -0.2098636292203786, 0.49616061555323165, 17.347955177020502, 41.63852136029957, 1740.4599485709577, 4465.686997292962, \'decentraland\'), (\'$0.03971905\', 73, -0.044662347745480384, 2.5641364000251783, 14.32887443738278, 50.95392720295576, 1149.0751719309608, 1771.1184920476167, \'siacoin\'), (\'$1.25\', 74, 0.10779713097099063, 2.2833705414573746, 6.098534668468114, 9.71676496957755, 465.28412719736264, 584.1798513440709, \'basic-attention-token\'), (\'$0.71042\', 75, -0.37730470310996544, -4.336611576669671, 126.17442779710333, 68.15541558229268, 2129.4862232395667, 15456.632666302317, \'fantom\'), (\'$48725\', 76, -0.15920128341745055, -0.0643597886284583, 12.550028956316982, 34.9838794070987, 195.2667649251738, NULL, \'yearn-finance\'), (\'$93.69\', 77, 0.02745277202123127, 3.6631559438085866, 5.651653720061815, 140.05973082018068, 1039.8296121955411, 849.6389750971346, \'bitcoin-gold\'), (\'$2.67\', 78, 1.783329034125296, -0.9242681101763994, 46.12246758287825, -12.14027471294288, 556.4682667597502, 852.9448575909419, \'icon\'), (\'$57176\', 79, -0.9533832019432645, 5.4317792239955445, 11.983119916380153, -2.750390523326744, 410.0913456810784, NULL, \'huobi-btc\'), (\'$0.179722\', 80, 2.8050956517740526, 7.164992733761393, 24.24997448247969, -4.324593161011476, 1206.4509988268217, 838.1701558629652, \'ravencoin\'), (\'$25.93\', 81, -0.22793614770735743, 3.2027633033030085, 11.024854097363939, 4.816910562350971, 172.81652257860964, 2007.562259446787, \'uma\'), (\'$14.63\', 82, -0.33137297614499905, 0.5992210646524218, 11.226074192541596, 56.067473583748026, 522.4709586686943, 853.5520143317111, \'qtum\'), (\'$1.01\', 83, 0.026322834540011168, 0.1273013937040994, -1.449818639739855, NULL, NULL, NULL, \'liquity-usd\'), (\'$0.065223\', 84, -0.09823453491625275, 4.541630666342533, 30.397030199769, 22.025808603745435, 1007.1427520748598, 1670.4775134661747, \'iostoken\'), (\'$1.79\', 85, -0.17529070532709334, 2.624803595390132, 17.68173014722982, 3.5382976449333503, 202.59941839448965, 265.5874145505618, \'ontology\'), (\'$1.81\', 86, 0.17788110321168346, 6.082805387938775, 22.52929911782539, -3.8803241353636317, 356.43617015925776, 808.1047113390014, \'0x\'), (\'$0.146094\', 87, 0.1290490678950675, 4.739264910511072, 37.655739989783285, -17.217535514022153, 2675.0727369853075, 5617.179890568806, \'harmony\'), (\'$16.66\', 88, 0.3354062249781931, -2.9097358613192785, 17.676087715862028, 58.455256085942395, 1101.3580995926743, 6842.466774484854, \'helium\'), (\'$120.81\', 89, -0.9234969081200384, 0.7613135352963638, 7.82417759584348, 135.57066100262716, 1862.5891974208703, 1958.7012419073762, \'zencash\'), (\'$7.34\', 90, -1.0220559016682336, 25.62516777827517, -43.69669254244453, 2119.578971338002, 9430.183809063274, 24430.30254234287, \'pirate-chain\'), (\'$6.94\', 91, 0.4421019469029953, 1.012648860154067, 9.907209442071787, -6.428447519267073, 400.5673048487242, 3316.675418168446, \'bancor\'), (\'$30.01\', 92, 0.04843776239411988, 0.01483471389123365, 53.800662585615186, -7.523942399036265, 526.5940011312427, 5976.902546090048, \'arweave\'), (\'$1.37\', 93, 3.566375353817102, 6.553013169892783, 26.78702981300144, 21.182819583857864, 1646.2175021734852, 7886.855820949487, \'swissborg\'), (\'$0.181141\', 94, 0.3671187880390468, 8.9903056390113, 30.42448177110424, 12.974417812978642, 2436.8143478804723, 11796.1322877156, \'ankr\'), (\'$2.79\', 95, -0.2581759324575599, -1.683115113441297, 5.7661135002319375, 252.71519108755913, 2726.8289728152995, 1877.3940066280045, \'wazirx\'), (\'$0.092264\', 96, 0.08980475261355543, 6.992402611541383, 19.853400880679747, 2.559421108648777, 872.9562725417502, 3655.5273556644565, \'reserve-rights-token\'), (\'$30.95\', 97, -0.3203659565343951, 0.566620664609878, 11.602095870638719, -9.869753825426269, NULL, NULL, \'flow\'), (\'$1\', 98, -0.17498227783436263, 0.0458534566140001, -0.2507806692487264, 0.09243695600429194, 0.015479175643923003, 0.22228495114712646, \'paxos-standard\'), (\'$15.03\', 99, -0.9438828115887875, 4.194180327562674, 32.279586110449486, 185.8609004296365, 1665.2973026299758, 1483.7224248930102, \'kucoin-shares\'), market_cap_rank = ?, price_change_percentage_1h_in_currency = ?, price_change_percentage_24h_in_currency = ?, price_change_percentage_7d_in_currency = ?, price_change_percentage_30d_in_currency = ?, price_change_percentage_200d_in_currency = ?, price_change_percentage_1y_in_currency = ? WHERE id = ?' }
MySQL的结构如下:

[ [ '$57453',
        1,
        -0.3420308363845882,
        5.572915018205854,
        12.233200940728546,
        -2.318933937220493,
        397.72609563393615,
        567.2380432044025,
        'bitcoin' ],
      [ '$2837.96',
        2,
        0.016409340109730643,
        2.1106445293246816,
        20.03746531858046,
        48.132112696446534,
        632.8398908252254,
        1280.6277298518,
        'ethereum' ],
      [ '$617.86',
        3,
        0.09529522096501872,
        -0.037445793001886205,
        17.06787284916119,
        104.0862961351894,
        1914.1435778621246,
        3538.5727910209353,
        'binancecoin' ],
      [ '$1.55',
        4,
        0.5061299537245372,
        0.8487206928960775,
        33.103999419202964,
        170.49836716961806,
        506.29510956451907,
        628.3743714018339,
        'ripple' ] ]

我做错了什么

编辑:以前使用的代码,不进行批处理

    for (const coin of marketDataUSD) {
        console.log("UPDATE")

        db.query('UPDATE coinDetail SET current_price = ?, market_cap_rank = ?, price_change_percentage_1h_in_currency = ?, price_change_percentage_24h_in_currency = ?, price_change_percentage_7d_in_currency = ?, price_change_percentage_30d_in_currency = ?, price_change_percentage_200d_in_currency = ?, price_change_percentage_1y_in_currency = ? WHERE id = ?',
                [coin.current_price,coin.market_cap_rank, coin.price_change_percentage_1h_in_currency, coin.price_change_percentage_24h_in_currency, coin.price_change_percentage_7d_in_currency, coin.price_change_percentage_30d_in_currency, coin.price_change_percentage_200d_in_currency, coin.price_change_percentage_1y_in_currency, coin.id], function (error, results, fields) {
            if(error) {
                console.log(error.message);
            }
        })
    }

将testvalue结构与实际查询参数顺序匹配,然后将
[testvalue]
更改为
testvalue
@lawrencerone。谢谢你的回答。你这是什么意思,能举个例子吗?