How to use the mssql.Request function in mssql

To help you get started, we’ve selected a few mssql 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 erickangMSFT / sqldevops / web_app / src / routes / backuphistory.js View on Github external
fs.readFile(sqlFile, 'utf8', (err, script) => {
        const request = new mssql.Request(pool);
        request.query(script, (err, rec) => {
            if (err) {
                const sqlerror = sqldevops.getSqlError(err);
                res.render('error', {
                    message: sqlerror.message,
                    error: sqlerror
                });
            }
            else {
                // for debugging
                // console.log(rec.recordset);
                res.render(viewName, {
                    title: title,
                    description: description,
                    nav: nav,
                    recordset: rec.recordset,
github erickangMSFT / sqldevops / web_app / src / routes / tablespacedetail.js View on Github external
router.get('/', (req, res, next) => {
  const request = new mssql.Request(pool);
  fs.readFile(tablespaceSqlFile, 'utf8', (err, script) => {
    const request = new mssql.Request(pool);
    request.query(script, (err, rec) => {
      if (err) {
        const sqlerror = sqldevops.getSqlError(err);
        res.render('error', {
          message: sqlerror.message,
          error: sqlerror
        });
      }
      else {
        // for debugging
        //console.log(rec.recordset);
        res.render('tablespacedetail', {
          title: 'Table Space Usage Detail',
          tablespaces: rec.recordset,
github erickangMSFT / sqldevops / web_app / src / routes / index.js View on Github external
pool.connect((err) => {
      const request = new mssql.Request(pool);
      request.query(script, (err, rec) => {
        if (err) {
          const sqlerror = sqldevops.getSqlError(err);
          res.render('error', {
            message: sqlerror.message,
            error: sqlerror
          });
        }
        else {
          // for debugging
          //console.log(rec.recordset);
          res.render('index', {
            title: 'Insights',
            nav: nav,
            tablespaces: rec.recordset,
            server: dbconfig.server,
github lukemurray / data-atom / lib / data-managers / sqlserver-manager.js View on Github external
(err) => {
          if (err) {
            return reject(this.buildError(err));
          }
          // Query
          var request = new sql.Request(connection);
          request.multiple = true;
          if (onQueryToken)
            onQueryToken(request);
          request.query(query,
            (err, recordset) => {
              if (err) {
                return reject(this.buildError(err));
              }
              resolve(this.translateResults(recordset));
            }
          );
        }
      );
github LeanKit-Labs / seriate / src / sqlContextUtils.js View on Github external
_.forEach( options.bulkLoadTable.columns, function( column, columnName ) {
		table.columns.add( columnName, column.type, { nullable: column.nullable === undefined ? true : column.nullable } );
	} );

	var columnNames = Object.keys( options.bulkLoadTable.columns );

	options.bulkLoadTable.rows.forEach( function( row ) {
		var values = columnNames.map( function( columnName ) {
			return row[ columnName ];
		} );

		table.rows.add.apply( table.rows, values );
	} );

	var req = new sql.Request( state.transaction || state.connection );

	return when.resolve()
	.then( function() {
		if ( !isTempTableName( options.bulkLoadTable.name ) ) {
			return;
		}

		var dropSql = "IF OBJECT_ID('tempdb.." + options.bulkLoadTable.name + "') IS NOT NULL DROP TABLE " + options.bulkLoadTable.name + ";";

		if ( !options.bulkLoadTable.useExisting ) {
			// Make sure we're not adding to an existing temp table
			nonPreparedSql( state, name + "-pre-drop", { query: dropSql } );
		}

		// Accumulate list of tables on state, which is the transaction object, to enforce appropriate scope
		// Keep this list to avoid double-dropping tables when we bulk load the same temp table more than once using `useExisting`
github totaljs / eshop / node_modules / sqlagent / sqlserver.js View on Github external
self.results[current.name] = rows;
				self.emit('data', current.name, self.results);
			}
			self.last = item.name;
			next();
		};

		if (item.type !== 'begin' && item.type !== 'end') {
			if (!current.first)
				current.first = isFIRST(current.query);

			if (Agent.debug)
				console.log(self.debugname, current.name, current.query);

			self.emit('query', current.name, current.query, current.params);
			var request = new database.Request(self.$transaction ? self.$transaction : self.db);
			if (current.params)
				prepare_params_request(request, current.params);
			request.query(current.query, query);
			return;
		}

		if (item.type === 'begin') {

			if (Agent.debug)
				console.log(self.debugname, 'begin transaction');

			self.$transaction = new database.Transaction(self.db);
			self.$transaction.begin(function(err) {
				if (err) {
					self.errors.push(err.message);
					self.command.length = 0;
github EasyERP / EasyERP_open_source / helpers / importer / connector / msSql.js View on Github external
transaction.begin(function (err) {
            var request;

            if (err) {
                return callback(err);
            }

            request = new sql.Request(transaction);
            request.query(query, function (err, recordset) {
                if (err) {
                    return callback(err);
                }

                callback(null, recordset);
                transaction.commit(function () {
                    console.log("Transaction committed.");
                });
            });
        });
github misterGF / sails-mssqlserver / lib / adapter.js View on Github external
return cb(err)
        }
        var schema = sql.schema(collection, definition)
        var schemaName = getSchemaName(connection, collection)
        var tableName = '[' + schemaName + ']' + '.[' + collection + ']'
        var statement = 'CREATE TABLE ' + tableName + ' (' + schema + ')'

        uniqId = uniqId || false
        var mssqlConnect
        if (!uniqId) {
          mssqlConnect = connections[connection].mssqlConnection
        } else {
          mssqlConnect = connections[connection].mssqlConnection[uniqId]
        }

        var request = new mssql.Request(mssqlConnect)
        request.query(statement, function (err, recordset) {
          if (err) {
            console.error('Error during query', err)
            return cb(err)
          }
          if (!connections[connection].persistent) {
            mssqlConnect && mssqlConnect.close()
          }
          cb(null, {})
        })
      })
    },
github DFEAGILEDEVOPS / MTC / admin / services / data-access / sql.service.js View on Github external
const query = async () => {
    let result = false
    if (redisKey) {
      try {
        const redisResult = await redisCacheService.get(redisKey)
        result = JSON.parse(redisResult)
      } catch (e) {}
    }
    if (!result) {
      const request = new mssql.Request(readonlyPool)
      addParamsToRequestSimple(params, request)
      result = await request.query(sql)
      if (redisKey) {
        await redisCacheService.set(redisKey, result)
      }
    }
    return sqlService.transformResult(result)
  }
github Kononnable / typeorm-model-generator / src / drivers / MssqlDriver.ts View on Github external
public async CreateDB(dbName: string) {
        const request = new MSSQL.Request(this.Connection);
        await request.query(`CREATE DATABASE ${dbName}; `);
    }