'use strict'
const mssql = require('./')
const { v4: uuid } = require('uuid')

const [, , max] = process.argv;

const sqlConfig = {
  password: 'Upper_l0wercase',
  database: 'di_production',
  stream: false,
  // driver: 'msnodesqlv8',
  options: {
    // trustedConnection: true,
    trustServerCertificate: true,
    enableArithAbort: true,
    encrypt: true,
    // abortTransactionOnError: false,
  },
  pool: {
    max: max ? parseInt(max) : 10,
    min: 0,
  },
  port: 1433,
  user: 'sa',
  server: 'localhost',
};

(async () => {
  const pools = await Promise.all(Array.from(new Array(100)).map(() => {
    return new mssql.ConnectionPool(sqlConfig).connect()
  }))
  setInterval(async () => {
    const pool = pools[Math.floor(Math.random() * pools.length)]
    const ps = new mssql.PreparedStatement(pool)
    ps.input('tempParam', mssql.TYPES.NVarChar)
    await ps.prepare('SELECT TOP 10 * FROM [debug] WHERE [tempData] = @tempParam')
    await ps.execute({ tempParam: '{}' })
    await ps.unprepare()
  }, 100)
})()
