1. <tfoot id='yodi6'></tfoot>
      <i id='yodi6'><tr id='yodi6'><dt id='yodi6'><q id='yodi6'><span id='yodi6'><b id='yodi6'><form id='yodi6'><ins id='yodi6'></ins><ul id='yodi6'></ul><sub id='yodi6'></sub></form><legend id='yodi6'></legend><bdo id='yodi6'><pre id='yodi6'><center id='yodi6'></center></pre></bdo></b><th id='yodi6'></th></span></q></dt></tr></i><div id='yodi6'><tfoot id='yodi6'></tfoot><dl id='yodi6'><fieldset id='yodi6'></fieldset></dl></div>

      <small id='yodi6'></small><noframes id='yodi6'>

      <legend id='yodi6'><style id='yodi6'><dir id='yodi6'><q id='yodi6'></q></dir></style></legend>

          <bdo id='yodi6'></bdo><ul id='yodi6'></ul>

        如何使用 node.js 在 mySQL 中进行批量插入

        时间:2023-08-18

        • <small id='fmCno'></small><noframes id='fmCno'>

              <bdo id='fmCno'></bdo><ul id='fmCno'></ul>

                    <tbody id='fmCno'></tbody>
                  <legend id='fmCno'><style id='fmCno'><dir id='fmCno'><q id='fmCno'></q></dir></style></legend>
                  <i id='fmCno'><tr id='fmCno'><dt id='fmCno'><q id='fmCno'><span id='fmCno'><b id='fmCno'><form id='fmCno'><ins id='fmCno'></ins><ul id='fmCno'></ul><sub id='fmCno'></sub></form><legend id='fmCno'></legend><bdo id='fmCno'><pre id='fmCno'><center id='fmCno'></center></pre></bdo></b><th id='fmCno'></th></span></q></dt></tr></i><div id='fmCno'><tfoot id='fmCno'></tfoot><dl id='fmCno'><fieldset id='fmCno'></fieldset></dl></div>
                  <tfoot id='fmCno'></tfoot>
                  本文介绍了如何使用 node.js 在 mySQL 中进行批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如果使用类似的东西,如何将批量插入到 mySQL 中https://github.com/felixge/node-mysql

                  How would one do a bulk insert into mySQL if using something like https://github.com/felixge/node-mysql

                  推荐答案

                  使用嵌套数组可以实现批量插入,参见 github 页面

                  Bulk inserts are possible by using nested array, see the github page

                  嵌套数组变成分组列表(用于批量插入),例如[['a', 'b'], ['c', 'd']] 变成 ('a', 'b'), ('c', 'd')

                  Nested arrays are turned into grouped lists (for bulk inserts), e.g. [['a', 'b'], ['c', 'd']] turns into ('a', 'b'), ('c', 'd')

                  您只需插入一个嵌套的元素数组.

                  You just insert a nested array of elements.

                  一个例子在这里

                  var mysql = require('mysql');
                  var conn = mysql.createConnection({
                      ...
                  });
                  
                  var sql = "INSERT INTO Test (name, email, n) VALUES ?";
                  var values = [
                      ['demian', 'demian@gmail.com', 1],
                      ['john', 'john@gmail.com', 2],
                      ['mark', 'mark@gmail.com', 3],
                      ['pete', 'pete@gmail.com', 4]
                  ];
                  conn.query(sql, [values], function(err) {
                      if (err) throw err;
                      conn.end();
                  });
                  

                  注意:values是包裹在数组中的数组

                  Note: values is an array of arrays wrapped in an array

                  [ [ [...], [...], [...] ] ]
                  

                  还有一个完全不同的node-msql包用于批量插入

                  There is also a totally different node-msql package for bulk insertion

                  这篇关于如何使用 node.js 在 mySQL 中进行批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 sql 结果中填充空日期的最直接方法是什么(在 下一篇:如何让 MySQL 正确处理 UTF-8

                  相关文章

                  最新文章

                  <legend id='W4gaL'><style id='W4gaL'><dir id='W4gaL'><q id='W4gaL'></q></dir></style></legend>
                  <tfoot id='W4gaL'></tfoot>
                    <bdo id='W4gaL'></bdo><ul id='W4gaL'></ul>
                  <i id='W4gaL'><tr id='W4gaL'><dt id='W4gaL'><q id='W4gaL'><span id='W4gaL'><b id='W4gaL'><form id='W4gaL'><ins id='W4gaL'></ins><ul id='W4gaL'></ul><sub id='W4gaL'></sub></form><legend id='W4gaL'></legend><bdo id='W4gaL'><pre id='W4gaL'><center id='W4gaL'></center></pre></bdo></b><th id='W4gaL'></th></span></q></dt></tr></i><div id='W4gaL'><tfoot id='W4gaL'></tfoot><dl id='W4gaL'><fieldset id='W4gaL'></fieldset></dl></div>

                  1. <small id='W4gaL'></small><noframes id='W4gaL'>