How to use the tedious.TYPES.NVarChar function in tedious

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
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 tediousjs / tedious / examples / bulkLoad-sample.js View on Github external
function loadBulkData() {
  var option = { keepNulls: true }; // option to honor null
  var bulkLoad = connection.newBulkLoad(table, option, function(err, rowCont) {
    if (err) {
      throw err;
    }
    console.log('rows inserted :', rowCont);
    connection.close();
  });
  // setup columns
  bulkLoad.addColumn('c1', TYPES.Int, { nullable: true });
  bulkLoad.addColumn('c2', TYPES.NVarChar, { length: 50, nullable: true });

  // add rows
  bulkLoad.addRow({ c2: 'hello' });
  bulkLoad.addRow({ c2: 'bulkLoad' });

  // perform bulk insert
  connection.execBulkLoad(bulkLoad);
}
github tediousjs / tedious / examples / parameters.js View on Github external
connection.on('connect', function(err){
	var request = new Request("INSERT INTO MyTable (uniqueIdCol, intCol, nVarCharCol) VALUES (@uniqueIdVal, @intVal, @nVarCharVal)",
	function(err){
		if(err){
			console.log(err);
		};
	});

	request.addParameter('uniqueIdVal', TYPES.UniqueIdentifierN,'ba46b824-487b-4e7d-8fb9-703acdf954e5');
	request.addParameter('intVal', TYPES.Int, 435);
	request.addParameter('nVarCharVal', TYPES.NVarChar, 'hello world');

	connection.execSql(request);
});
github hackforla / tdm-calculator / app / services / account-service.js View on Github external
await mssql.executeProc("SecurityToken_Insert", sqlRequest => {
      sqlRequest.addParameter("token", TYPES.NVarChar, token);
      sqlRequest.addParameter("email", TYPES.NVarChar, email);
    });
github Azure-Samples / openhack-devops-team / apis / userprofile / data / user / {userID}.js View on Github external
200: function (req, res, callback) {

            req.sql(queries.SELECT_USER_PROFILE_BY_ID)
                .param('user_profile_id', req.params.userID, TYPES.NVarChar)
                .into(res, '{}');
            callback;
          
        },
        default: function (req, res, callback) {
github DFEAGILEDEVOPS / MTC / admin / services / data-access / role.data.service.js View on Github external
sqlFindOneByTitle: async (roleTitle) => {
    const params = [
      {
        name: 'roleTitle',
        value: roleTitle,
        type: TYPES.NVarChar
      }
    ]
    const result = await sqlService.query(`SELECT TOP 1 [id], [title] FROM ${sqlService.adminSchema}.${table} WHERE title=@roleTitle`, params)
    return R.head(result)
  }
}
github DFEAGILEDEVOPS / MTC / design / census-import / generate-school-records.js View on Github external
winston.info('Generating schools...')
    const dfeNumbers = []
    for (let i = 0; i < schoolsLength; i++) {
      let estabCode = 1006 + i
      const schoolNumber = converter.toWords(6 + i)
      const exampleSchoolNumber = schoolNumber.charAt(0).toUpperCase() + schoolNumber.slice(1)
      estabCode = estabCode.toString()
      let name = `Example School ${exampleSchoolNumber}`
      const dfeNumber = 9991006 + i
      dfeNumbers.push(dfeNumber)
      const urn = 89006 + i
      const params = [
        {
          name: 'estabCode',
          value: estabCode,
          type: TYPES.NVarChar
        },
        {
          name: 'name',
          value: name,
          type: TYPES.NVarChar
        },
        {
          name: 'urn',
          value: urn,
          type: TYPES.Int
        },
        {
          name: 'dfeNumber',
          value: dfeNumber,
          type: TYPES.Int
        }
github Azure-Samples / openhack-devops-team / apis / userprofile / data / user / {userID}.js View on Github external
201: function (req, res, callback) {
            
            req.sql(queries.INSERT_USER_PROFILE)
                .param('UserProfileJson', req.body, TYPES.NVarChar)
                .exec(res);
            callback;
        
        },
        default: function (req, res, callback) {