Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

64
Views
sql table's data to array javascript

I have JavaScript code below that connect to the database and SELECT table

//Connect to database
  var sql = require("mssql");

  var config = {
  user: '****',
  password: '*****',
  server: '****',
  databse:'****',
  };
  
  sql.connect(config)
      var request = new sql.Request();
      // query to the database and get the records
      request.query("select * from Test ")

below is the terminal output.

 recordset: [
    { ID: '0      ', Name: 'Test1     ', Age: '80        ' },
    { ID: '1      ', Name: 'Test2      ', Age: '55        ' }
  ],

So I need to make array below take all data from recordset, so I can use the array in other functions

var users = [{}]

when open the page on the browser the var users should look

users = [
    { ID: '0', Name: 'Test1', Age: '80' },
    { ID: '1', Name: 'Test2', Age: '55' }
  ]
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

If you already have recordset in desired format and you want it to be users, you can do this:

var users = recordset; 

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs