How do I do a bulk insert in mySQL using node.js

后端 未结 12 2459
一整个雨季
一整个雨季 2020-11-22 10:39

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

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 11:10

    If you want to insert object, use this:

        currentLogs = [
     { socket_id: 'Server', message: 'Socketio online', data: 'Port  3333', logged: '2014-05-14 14:41:11' },
     { socket_id: 'Server', message: 'Waiting for Pi to connect...', data: 'Port: 8082', logged: '2014-05-14 14:41:11' }
    ];
    
    console.warn(currentLogs.map(logs=>[ logs.socket_id , logs.message , logs.data , logs.logged ]));
    

    The output will be:

    [
      [ 'Server', 'Socketio online', 'Port  3333', '2014-05-14 14:41:11' ],
      [
        'Server',
        'Waiting for Pi to connect...',
        'Port: 8082',
        '2014-05-14 14:41:11'
      ]
    ]
    

    Also, please check the documentation to know more about the map function.

提交回复
热议问题