How to use the Table function from mssql

Find comprehensive JavaScript mssql.Table code examples handpicked from public code repositorys.

495
496
497
498
499
500
501
502
503
504
505
      return res.status(500).json(err);
    });
});


app.get('/bulk', (req, res) => {
  const table = new sql.Table('AnotherUserTable');
  table.create = true;
  table.columns.add('name', sql.NVarChar(40), { nullable: true });
  table.columns.add('email', sql.NVarChar(40), { nullable: true });
  table.rows.add('Domitian', 'domitian@flavius.com');
fork icon34
star icon66
watch icon0

40
41
42
43
44
45
46
47
48
49
pool.connect()
  .then(async () => {
    // schools
    console.log('connected')
    console.log(`inserting ${schoolCount} schools...`)
    const table = new sql.Table('mtc_admin.school')
    table.create = false
    table.columns.add('leaCode', sql.Int, { nullable: false })
    table.columns.add('estabCode', sql.Int, { nullable: false })
    table.columns.add('name', sql.NVarChar, { length: 'max', nullable: false })
fork icon14
star icon12
watch icon11

+ 17 other calls in file

66
67
68
69
70
71
72
73
74
75
    }
});
router.post('/many', async (req, res) => {
    try {
        await pool.connect();
        const employeesTable = new mssql.Table();

        employeesTable.columns.add('Code', mssql.VarChar(50));
        employeesTable.columns.add('Name', mssql.VarChar(50));
        employeesTable.columns.add('Job', mssql.VarChar(50));
fork icon7
star icon10
watch icon2

59
60
61
62
63
64
65
66
67
68
                                    if (req.object.parameters[item].io == 2)
                                            return req.object.parameters[item].value;
                    }
                    return null;
            },
            table: () => { return new sql.Table(); },
            execute: sqlExecute
};

    return req;
fork icon3
star icon1
watch icon6

+ 9 other calls in file

33
34
35
36
37
38
39
40
41
42
const Int = sql.Int;
const BigInt = sql.BigInt;
const Varchar = (length) => sql.VarChar(length);
const NVarchar = (length) => sql.NVarChar(length);
const Decimal = (digits, precision) => sql.Decimal(digits, precision);
const Table = () => new sql.Table();

export {
  connection,
  Bit,
fork icon0
star icon4
watch icon2

86
87
88
89
90
91
92
93
94
95

/**
 * @param {String} tableName Name of the temp table to use
 * @param {{}[]} columns Array of column objects to use
 * @param {[][]} collection Array of arrays containing
 * @return {Object} new mssql.Table
 */
function generateTable(tableName, columns, collection) {
  var _table = new mssql.Table(tableName);
  // Set table creation to true, to ensure the table is created if it doesn't exist,
fork icon1
star icon0
watch icon4

+ 3 other calls in file

73
74
75
76
77
78
79
80
81
82
// loadTempTable: Load batch of rows into temp table
function loadTempTable(tableArr, numCols) {
  return new Promise((resolve, reject) => {
    try {
      // create a generic temp table with same number of cols as target.
      const table = new sql.Table(tempTablename);
      table.create = true;

      for (let x = 0; x < numCols; x += 1) {
        table.columns.add(`col${x}`, sql.VarChar(8000), { nullable: true });
fork icon1
star icon1
watch icon0

90
91
92
93
94
95
96
97
98
if(gameMode == GAME_TYPES.DEAL){
    request.amt = parseFloat(contestData.ja);
}
loggerError.gameLog(request.gameserverid, `Calculating the amt and mba`, request.amt, request.mba);

var tbl_UserList = new sql.Table();
tbl_UserList.columns.add("UserId", sql.VarChar, { nullable: true });
tbl_UserList.columns.add("UserLoginId", sql.BigInt, { nullable: true });
tbl_UserList.columns.add("ReferCode", sql.VarChar, { nullable: true });
fork icon0
star icon0
watch icon1

+ 19 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14


module.exports = (config, getVerify, params, callback) => {
    console.log(params)
    const requestParams = config.dbwrapper.getNewRequest();


    let APIUnitAvailable = new mssql.Table();
    APIUnitAvailable.columns.add('UnitId', mssql.Int);
    APIUnitAvailable.columns.add('StartDate', mssql.NVarChar);
    APIUnitAvailable.columns.add('Enddate', mssql.NVarChar);
    APIUnitAvailable.columns.add('IsAvailable', mssql.Bit);
fork icon0
star icon0
watch icon1

+ 15 other calls in file

11
12
13
14
15
16
17
18
19
20
21
22
}


async function insertCommercialRelease(commercialRelease){


    //Creando la tabla UDT
    var udtCommercialRelease = new sql.Table();
    // Las columnas deben corresponder con las creadas en la base de datos.   
    udtCommercialRelease.columns.add('Id_Item', sql.VarChar(50));  
    udtCommercialRelease.columns.add('Id_Country', sql.VarChar(10));
    udtCommercialRelease.columns.add('Id_Status_Commercial_Release', sql.SmallInt(2));
fork icon0
star icon0
watch icon0

33
34
35
36
37
38
39
40
41
42
43
44
45
}, process.env.CRAWLER_INTERVAL);




   function create(conn){


      const table = new sql.Table('BTCUSDT');
      table.create = true;
      table.columns.add('COIN', sql.NVarChar(50), {nullable: false});
      table.columns.add('TIMEOPEN', sql.DateTime);
      table.columns.add('OPEN', sql.NVarChar(50), {nullable: false});
fork icon0
star icon0
watch icon0

+ 7 other calls in file

49
50
51
52
53
54
55
56
57
58
//     console.log('error sql on damage', err);
// })

//console.log(req.body)

const tvp = new sql.Table();
tvp.columns.add('ActID', sql.BigInt);
tvp.columns.add('Letters', sql.NVarChar(20));
tvp.columns.add('Side', sql.SmallInt);
tvp.columns.add('StaffID', sql.BigInt);
fork icon0
star icon0
watch icon1

23
24
25
26
27
28
29
30
31
32
const trac = await axios.create(config).get(`${project.Url}query?id=${ticket.TracId}${project.UrlColumnsAll}&format=csv`)
let tracTickets = CSV.parse(trac.data);
tracTickets.splice(0,1)
const tracTicket = tracTickets[0]

const tvp = new sql.Table()
tvp.columns.add('TracId', sql.Int)
tvp.columns.add('Summary', sql.NVarChar(200), {nullable: true})
tvp.columns.add('Status', sql.NVarChar(200), {nullable: true})
tvp.columns.add('Owner', sql.NVarChar(200), {nullable: true})
fork icon0
star icon0
watch icon1

+ 5 other calls in file

147
148
149
150
151
152
153
154
155
156


let bulkInsertGenerator = (tableName, data, model) => {
  return new Promise((resolve, reject) => {
    connect.then(pool => {
      let table = new sql.Table(tableName);
      table.create = false;
      tableColumnsAdd(model, table);
      _.each(data, each => {
        table.rows.push(alignObjData(each, model))
fork icon0
star icon0
watch icon2

+ 3 other calls in file

172
173
174
175
176
177
178
179
180
181


var tableName = isTemp
    ? 'TempAccount'
    : 'Account';
var table = new mssql.Table(tableName); // or temporary table, e.g. #temptable
//table.create = true;
table.columns.add('@url', mssql.NVarChar(mssql.MAX), {nullable: true});
table.columns.add('Active', mssql.Bit, {nullable: true});
table.columns.add('Description', mssql.NVarChar(200), {nullable: false});
fork icon0
star icon0
watch icon5