How to use the tedious.Request 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 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 DFEAGILEDEVOPS / MTC / admin / data / sql / createDatabase.js View on Github external
return new Promise((resolve, reject) => {
    const results = []
    // http://tediousjs.github.io/tedious/api-request.html
    var request = new Request(sql, function (err, rowCount) {
      if (err) {
        return reject(err)
      }
      return resolve(results)
    })

    request.on('row', function (cols) {
      results.push(cols)
    })
    connection.execSql(request)
  })
}
github Azure / meta-azure-service-broker / test / utils / azuresqldbClient.js View on Github external
function(callback) {
        var request = new Request('SELECT * FROM testtable', function(err) {
          var message = 'The user can %sget the row inserted.';
          nextStep(err, message, callback);
        });
        connection.execSql(request);
      }
    ],function(err){
github Azure / azure-sql-database-samples / node.js / linux / sample_nodejs_linux.js View on Github external
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);
        result ="";
    });
github erhangundogan / sql2mongodb / sql.js View on Github external
var queryString = [];
      /*
       select SUM(rows) As Rows
       from sys.partitions p
       left join sys.objects o on o.object_id = p.object_id
       where (p.index_id in (0,1)) and (o.is_ms_shipped = 0) and (o.type_desc = 'USER_TABLE') and (o.name = 'table')
       */
      queryString.push("SELECT SUM(rows) AS Rows");
      queryString.push("FROM sys.partitions p");
      queryString.push("LEFT JOIN sys.objects o ON o.object_id = p.object_id");
      queryString.push("WHERE (p.index_id in (0,1)) AND (o.is_ms_shipped = 0) AND");
      queryString.push("(o.type_desc = 'USER_TABLE') AND o.name = ");
      queryString.push("('"+table+"')");
      var query = queryString.join(" ");

      var request = new Request(query, function(err, rowCount) {
        if (err) {
          console.log(err);
          callback(err, null);
        }
      });

      request.on("row", function(result) {
        callback(null, result[0].value);
      });

      conn.execSql(request);
    }
  });
github twright-msft / mssql-node-docker-demo-app / server.js View on Github external
conn.on('connect', function(err) {
        if (err) {
            console.log(err);
        } else {
            sqlreq = new request("SELECT * FROM Products FOR JSON AUTO", function(err, rowCount) {
                if (err) {
                    console.log(err);
                }
            });

            sqlreq.on('row', function(columns) { 
                columns.forEach(function(column) {  
                    if (column.value === null) {  
                        console.log('NULL');
                    } else {  
                        res.send(column.value);
                    }  
                });
            });

            conn.execSql(sqlreq);
github tinkerscript / sqlssb / source / dataAdapter.js View on Github external
return new Promise((resolve, reject) => {
      const request = new Request(query, err => {
        if (err) {
          reject(err)
        } else {
          resolve()
        }
        connection.close()
      })

      request.addParameter('body', TYPES.VarChar, body)
      request.addParameter('target', TYPES.VarChar, target)
      connection.execSql(request)
    })
  }
github tediousjs / node-mssql / lib / tedious / request.js View on Github external
}
        }

        const bulk = connection.newBulkLoad(table.path, options, done)

        for (const col of table.columns) {
          bulk.addColumn(col.name, getTediousType(col.type), { nullable: col.nullable, length: col.length, scale: col.scale, precision: col.precision })
        }

        for (const row of table.rows) {
          bulk.addRow(row)
        }

        if (table.create) {
          const objectid = table.temporary ? `tempdb..[${table.name}]` : table.path
          const req = new tds.Request(`if object_id('${objectid.replace(/'/g, '\'\'')}') is null ${table.declare()}`, err => {
            if (err) return done(err)

            connection.execBulkLoad(bulk)
          })
          this._setCurrentRequest(req)

          connection.execSqlBatch(req)
        } else {
          connection.execBulkLoad(bulk)
        }
      })
    })
github DFEAGILEDEVOPS / MTC / pupil-api / src / migrator / databaseCreator.ts View on Github external
return new Promise((resolve, reject) => {
      let results = []
      const request = new Request(sql, function (err, rowCount) {
        if (err) {
          return reject(err)
        }
        return resolve(results)
      })

      request.on('row', function (cols) {
        results.push(cols)
      })
      connection.execSql(request)
    })
  }
github Azure / node-red-contrib-azure / azuresql.js View on Github external
function executeStatement() {  
        request = new Request(queryString, function(err, rowCount, rows) {  
                node.log(rowCount + " rows returned");
            if (err) {  
                setStatus(statusEnum.error);
                node.error('Error: ' +JSON.stringify(err));
                node.log('Error: ' +JSON.stringify(err));
            }
        }); 
        var result = [];
        var columnDetails= {};

        request.on('row', function(columns) {  
            columns.forEach(function(column) {  
              if (column.value === null) {  
                node.log('NULL');  
              } else {  
                let columnName = column.metadata.colName;