Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sql = require('mssql')
- const config = {
- user: '',
- password: '',
- server: '', // You can use 'localhost\\instance' to connect to named instance
- database: '',
- domain:'',
- options: {
- encrypt: false // Use this if you're on Windows Azure
- }
- }
- module.exports.insertBulk = async (data) => {
- try {
- const pool = await sql.connect(config);
- const table = new sql.Table('BillingService.dbo.StagingIncomingPayments');
- table.create = false;
- // guess Id is auto generated
- // table.columns.add('Id', sql.Int, {nullable: false, primary: true});
- table.columns.add('TowId', sql.NVarChar(50), {nullable: false});
- table.columns.add('WorkType', sql.NVarChar(50), {nullable: false});
- table.columns.add('WorkDate', sql.DateTime, {nullable: false});
- table.columns.add('ContractorId', sql.NVarChar(50), {nullable: false});
- table.columns.add('RegionCode', sql.NVarChar(50), {nullable: false});
- table.columns.add('ItemCode', sql.NVarChar(50), {nullable: false});
- table.columns.add('Quantity', sql.Int, {nullable: false});
- // table.columns.add('TimeStamp', sql.NVarChar(50), {nullable: true});
- data.map((record) => {
- table.rows.add(record.TowId, record.WorkType, record.WorkDate,
- record.ContractorId, record.RegionCode, record.ItemCode, record.Quantity);
- });
- const request = new sql.Request()
- await request.bulk(table, (err, result) => {
- if (err) {
- console.log(err);
- }
- else {
- console.log(result);
- pool.close();
- }
- });
- } catch (err) {
- console.log(err)
- }
- }
Add Comment
Please, Sign In to add comment