How to use tedious - 10 common examples

To help you get started, we’ve selected a few tedious examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DFEAGILEDEVOPS / MTC / spike-worker / bulkImport.js View on Github external
// optional BulkLoad options
  const options = {keepNulls: true}

  // instantiate - provide the table where you'll be inserting to, options and a callback
  const bulkLoad = connection.newBulkLoad(`${config.Sql.Database}.[mtc_admin].[pupil]`, options, function (error, rowCount) {
    if (error) {
      console.error('import failed...')
      console.error(error)
    }
    console.log('inserted %d rows', rowCount)
  })

  // setup your columns - always indicate whether the column is nullable
  // TODO add all fields that are being imported to this list
  bulkLoad.addColumn('school_id', TYPES.Int, {nullable: false})
  bulkLoad.addColumn('upn', TYPES.Char, {length: 13, nullable: false})
  bulkLoad.addColumn('lastName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('foreName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('middleNames', TYPES.NVarChar, {length: 'max', nullable: true})
  bulkLoad.addColumn('gender', TYPES.Char, {length: 1, nullable: false})
  bulkLoad.addColumn('dateOfBirth', TYPES.DateTimeOffset, {nullable: false})

  const schools = schoolLookupDisabled ? schoolData : await schoolLookup(csvPayload)
  for (let index = 0; index < csvPayload.length; index++) {
    const csvRow = csvPayload[index]
    const dfeNumber = `${csvRow[0]}${csvRow[1]}`
    const school = schools.find(s => s.dfeNumber === parseInt(dfeNumber))
    const schoolId = school && school.id
    if (!schoolId) {
      console.error(`School id not found for DfeNumber ${dfeNumber}`)
      process.exit(1)
github DFEAGILEDEVOPS / MTC / spike-worker / bulkImport.js View on Github external
const options = {keepNulls: true}

  // instantiate - provide the table where you'll be inserting to, options and a callback
  const bulkLoad = connection.newBulkLoad(`${config.Sql.Database}.[mtc_admin].[pupil]`, options, function (error, rowCount) {
    if (error) {
      console.error('import failed...')
      console.error(error)
    }
    console.log('inserted %d rows', rowCount)
  })

  // setup your columns - always indicate whether the column is nullable
  // TODO add all fields that are being imported to this list
  bulkLoad.addColumn('school_id', TYPES.Int, {nullable: false})
  bulkLoad.addColumn('upn', TYPES.Char, {length: 13, nullable: false})
  bulkLoad.addColumn('lastName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('foreName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('middleNames', TYPES.NVarChar, {length: 'max', nullable: true})
  bulkLoad.addColumn('gender', TYPES.Char, {length: 1, nullable: false})
  bulkLoad.addColumn('dateOfBirth', TYPES.DateTimeOffset, {nullable: false})

  const schools = schoolLookupDisabled ? schoolData : await schoolLookup(csvPayload)
  for (let index = 0; index < csvPayload.length; index++) {
    const csvRow = csvPayload[index]
    const dfeNumber = `${csvRow[0]}${csvRow[1]}`
    const school = schools.find(s => s.dfeNumber === parseInt(dfeNumber))
    const schoolId = school && school.id
    if (!schoolId) {
      console.error(`School id not found for DfeNumber ${dfeNumber}`)
      process.exit(1)
    }
    bulkLoad.addRow({
github DFEAGILEDEVOPS / MTC / spike-worker / bulkImport.js View on Github external
// instantiate - provide the table where you'll be inserting to, options and a callback
  const bulkLoad = connection.newBulkLoad(`${config.Sql.Database}.[mtc_admin].[pupil]`, options, function (error, rowCount) {
    if (error) {
      console.error('import failed...')
      console.error(error)
    }
    console.log('inserted %d rows', rowCount)
  })

  // setup your columns - always indicate whether the column is nullable
  // TODO add all fields that are being imported to this list
  bulkLoad.addColumn('school_id', TYPES.Int, {nullable: false})
  bulkLoad.addColumn('upn', TYPES.Char, {length: 13, nullable: false})
  bulkLoad.addColumn('lastName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('foreName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('middleNames', TYPES.NVarChar, {length: 'max', nullable: true})
  bulkLoad.addColumn('gender', TYPES.Char, {length: 1, nullable: false})
  bulkLoad.addColumn('dateOfBirth', TYPES.DateTimeOffset, {nullable: false})

  const schools = schoolLookupDisabled ? schoolData : await schoolLookup(csvPayload)
  for (let index = 0; index < csvPayload.length; index++) {
    const csvRow = csvPayload[index]
    const dfeNumber = `${csvRow[0]}${csvRow[1]}`
    const school = schools.find(s => s.dfeNumber === parseInt(dfeNumber))
    const schoolId = school && school.id
    if (!schoolId) {
      console.error(`School id not found for DfeNumber ${dfeNumber}`)
      process.exit(1)
    }
    bulkLoad.addRow({
      school_id: schoolId,
github DFEAGILEDEVOPS / MTC / spike-worker / bulkImport.js View on Github external
const bulkLoad = connection.newBulkLoad(`${config.Sql.Database}.[mtc_admin].[pupil]`, options, function (error, rowCount) {
    if (error) {
      console.error('import failed...')
      console.error(error)
    }
    console.log('inserted %d rows', rowCount)
  })

  // setup your columns - always indicate whether the column is nullable
  // TODO add all fields that are being imported to this list
  bulkLoad.addColumn('school_id', TYPES.Int, {nullable: false})
  bulkLoad.addColumn('upn', TYPES.Char, {length: 13, nullable: false})
  bulkLoad.addColumn('lastName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('foreName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('middleNames', TYPES.NVarChar, {length: 'max', nullable: true})
  bulkLoad.addColumn('gender', TYPES.Char, {length: 1, nullable: false})
  bulkLoad.addColumn('dateOfBirth', TYPES.DateTimeOffset, {nullable: false})

  const schools = schoolLookupDisabled ? schoolData : await schoolLookup(csvPayload)
  for (let index = 0; index < csvPayload.length; index++) {
    const csvRow = csvPayload[index]
    const dfeNumber = `${csvRow[0]}${csvRow[1]}`
    const school = schools.find(s => s.dfeNumber === parseInt(dfeNumber))
    const schoolId = school && school.id
    if (!schoolId) {
      console.error(`School id not found for DfeNumber ${dfeNumber}`)
      process.exit(1)
    }
    bulkLoad.addRow({
      school_id: schoolId,
      upn: csvRow[2],
      lastName: csvRow[3],
github DFEAGILEDEVOPS / MTC / spike-worker / bulkImport.js View on Github external
if (error) {
      console.error('import failed...')
      console.error(error)
    }
    console.log('inserted %d rows', rowCount)
  })

  // setup your columns - always indicate whether the column is nullable
  // TODO add all fields that are being imported to this list
  bulkLoad.addColumn('school_id', TYPES.Int, {nullable: false})
  bulkLoad.addColumn('upn', TYPES.Char, {length: 13, nullable: false})
  bulkLoad.addColumn('lastName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('foreName', TYPES.NVarChar, {length: 'max', nullable: false})
  bulkLoad.addColumn('middleNames', TYPES.NVarChar, {length: 'max', nullable: true})
  bulkLoad.addColumn('gender', TYPES.Char, {length: 1, nullable: false})
  bulkLoad.addColumn('dateOfBirth', TYPES.DateTimeOffset, {nullable: false})

  const schools = schoolLookupDisabled ? schoolData : await schoolLookup(csvPayload)
  for (let index = 0; index < csvPayload.length; index++) {
    const csvRow = csvPayload[index]
    const dfeNumber = `${csvRow[0]}${csvRow[1]}`
    const school = schools.find(s => s.dfeNumber === parseInt(dfeNumber))
    const schoolId = school && school.id
    if (!schoolId) {
      console.error(`School id not found for DfeNumber ${dfeNumber}`)
      process.exit(1)
    }
    bulkLoad.addRow({
      school_id: schoolId,
      upn: csvRow[2],
      lastName: csvRow[3],
      foreName: csvRow[4],
github Azure / azure-sql-database-samples / node.js / windows / sample_nodejs_win.js View on Github external
password: 'yourpassword',
    server: 'yourserver.database.windows.net',
    // When you connect to Azure SQL Database, you need these next options.
    options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
    // If no error, then good to proceed.
    console.log("Connected");
    executeStatement();
    //executeStatement1();

});

var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

function executeStatement() {
    request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
    if (err) {
        console.log(err);} 
    });
    var result = "";
    request.on('row', function(columns) {
        columns.forEach(function(column) {
          if (column.value === null) {
            console.log('NULL');
          } else {
            result+= column.value + " ";
          }
        });
        console.log(result);
github Azure / azure-sql-database-samples / node.js / linux / sample_nodejs_linux.js View on Github external
userName: 'yourusername',
    password: 'yourpassword',
    server: 'yourserver.database.windows.net',
    // When you connect to Azure SQL Database, you need these next options.
    options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
    // If no error, then good to proceed.
    console.log("Connected");
    executeStatement();

});

var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

function executeStatement() {
    request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
    if (err) {
        console.log(err);} 
    });
    var result = "";
    request.on('row', function(columns) {
        columns.forEach(function(column) {
          if (column.value === null) {
            console.log('NULL');
          } else {
            result+= column.value + " ";
          }
        });
        console.log(result);
github erhangundogan / sql2mongodb / sql.js View on Github external
connection.on("connect", function(err) {
          if (err) {
            console.log(err);
            callback(err, null);
          } else {
            request = new Request(query, function(err) {
              if (err) {
                console.log(err);
                return callback(err, null);
              }
            });

            // should process columns again, because it may be changed
            request.on("columnMetadata", function(allColumns) {
              if (insertRows === 0) {
                var columnItem = {};

                for (var idx in allColumns) {
                  columnItem = allColumns[idx];
                  schema[columnItem.colName] = types[columnItem.type.name];
                }
                ItemSchema = new Schema(schema);
github microsoft / mssql-docker / oss-drivers / tedious / sample.js View on Github external
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

// Create connection to database
var config = {
  userName: '$DB_USERNAME', // update me
  password: '$DB_PASSWORD', // update me
  server: '$DB_HOST'
}
var connection = new Connection(config);

// Attempt to connect and execute queries if connection goes through
connection.on('connect', function(err) {
  if (err) {
    console.log(err);
  } else {
    console.log('Connected');
  }
});
github Azure / azure-sql-database-samples / node.js / windows / sample_nodejs_win.js View on Github external
var Connection = require('tedious').Connection;
var config = {
    userName: 'yourusername',
    password: 'yourpassword',
    server: 'yourserver.database.windows.net',
    // When you connect to Azure SQL Database, you need these next options.
    options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
    // If no error, then good to proceed.
    console.log("Connected");
    executeStatement();
    //executeStatement1();

});

var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

function executeStatement() {
    request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
    if (err) {
        console.log(err);} 
    });