How to use the Int function from mssql

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

mssql.Int is a class that represents a Int data type in SQL Server in Node.js.

143
144
145
146
147
148
149
150
151
152
case 'smallint':
    type = mssql.SmallInt;
    
    break;
case 'int':
    type = mssql.Int;
    
    break;
case 'bigint':
    type = mssql.BigInt;
fork icon6
star icon6
watch icon1

28
29
30
31
32
33
34
35
36
37
};

const Bit = sql.Bit;
const TinyInt = sql.TinyInt;
const SmallInt = sql.SmallInt;
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);
fork icon0
star icon4
watch icon2

+ 3 other calls in file

How does mssql.Int work?

In the MSSQL Node.js module, mssql.Int is a data type that represents a 32-bit integer. It can be used to define parameter values for SQL queries and stored procedures that expect integer input. When the query is executed, the mssql module automatically converts the value to the appropriate data type for the database.

76
77
78
79
80
81
82
83
84
85
SqlHelperMssql.mssqlType = function(fieldType)
{
        var typeName = SqlHelperMssql.typeName(fieldType);

        if (typeName == 'text') return mssql.NVarChar;
        else if (typeName == 'integer') return mssql.Int;
        else if (typeName == 'decimal') return mssql.Float; //TODO - use decimal?
        else if (typeName == 'timestamp') return mssql.VarChar(256); //TODO - use real js dates?
        else if (typeName == 'date') return mssql.VarChar(256); //TODO - use real js dates?
        else if (typeName == 'float') return mssql.Float;
fork icon0
star icon2
watch icon3

+ 21 other calls in file

202
203
204
205
206
207
208
209
210
211

if (err)
    console.log(err);

var request = new sql.Request();
request.input('id', sql.Int(), req.body.id)
    .query("delete from MarkerList where id = @id", function (err, recordset) {
        if (err) {
            console.log(err)
            res.send(err);
fork icon1
star icon1
watch icon2

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const sql = require("mssql");

const pool = new sql.ConnectionPool({
  user: "myusername",
  password: "mypassword",
  server: "localhost",
  database: "mydatabase",
});

pool
  .connect()
  .then(async () => {
    const request = new sql.Request(pool);
    const myInt = sql.Int(42); // creating an instance of the Int data type with a value of 42
    request.input("myIntParam", myInt);
    const result = await request.query(
      "SELECT * FROM mytable WHERE mycolumn = @myIntParam"
    );
    console.log(result);
  })
  .catch((err) => {
    console.error(err);
  });

In this example, we create a new instance of the sql.Int data type with a value of 42, and use it as a parameter in a SQL query using the request.input() method. The query returns all rows from a table called mytable where the value of a column called mycolumn is equal to the value of the parameter. The result of the query is logged to the console.

309
310
311
312
313
314
315
316
317
318
function getType(value, param) {
  let type = mssql.NVarChar
  if (param && param.type) {
    switch (param.type) {
      case 'integer':
        type = mssql.Int
        break
      case 'number':
        type = mssql.Decimal(param.maxLength, param.decimals)
        break
fork icon1
star icon0
watch icon2

88
89
90
91
92
93
94
95
96
97

//connecting to the DB
const pool = await sql.connect(con);
const result = await pool
  .request() // need to find the (hashed)password information matching the accountid
  .input("accountid", sql.Int(), account.accountid) // setting up the accountid as SQL variable, the value is in the account object
  .query(`
                  SELECT *
                  FROM bgPassword p
                  WHERE p.FK_accountid = @accountid
fork icon0
star icon0
watch icon2

+ 8 other calls in file

60
61
62
63
64
65
66
67
68
69
console.log("started try and catch bloc");
const account = await Account.findAccountByUser(credObj.email);
const pool = await sql.connect(con);
const result = await pool
  .request()
  .input("accountId", sql.Int(), account.accountId)
  .query(
    `SELECT *
  FROM stuorgPassword p
  WHERE p.FK_accountId = @accountId`
fork icon0
star icon0
watch icon0

+ 21 other calls in file

72
73
74
75
76
77
78
79
80
81
switch(typeName) {
    case 'sql.Bit':              return sql.Bit;
    case 'sql.BigInt':           return sql.BigInt;
    case 'sql.Decimal':          return sql.Decimal;
    case 'sql.Float':            return sql.Float;
    case 'sql.Int':              return sql.Int;
    case 'sql.Money':            return sql.Money;
    case 'sql.Numeric':          return sql.Numeric;
    case 'sql.SmallInt':         return sql.SmallInt ;
    case 'sql.SmallMoney':       return sql.SmallMoney;
fork icon0
star icon0
watch icon0

+ 5 other calls in file

118
119
120
121
122
123
124
125
126
127
  break;
case 'image':
  type = mssql.Image();
  break;
case 'int':
  type = mssql.Int();
  break;
case 'money':
  type = mssql.Money();
  break;
fork icon0
star icon0
watch icon1

+ 3 other calls in file