import fs from 'fs' ; import mssql from 'mssql' ; import path from 'path' ; import { URL } from 'url' ; export type SetupParams = { connectionString : string ; dirname : string ; } ; function getMSSQLConfig ( url ) { const connectionUrl = new URL ( url ) ; return { user : connectionUrl . username , password : connectionUrl . password , server : connectionUrl . hostname , port : Number ( connectionUrl . port ) , database : connectionUrl . pathname . substring ( 1 ) , pool : { max : 1 , } , options : { enableArithAbort : false , trustServerCertificate : true , } , } ; } export async function setupMSSQL ( options ) { const { connectionString } = options ; const { dirname } = options ; const schema = fs . readFileSync ( path . join ( dirname , 'setup.sql' ) , 'utf-8' ) ; const config = getMSSQLConfig ( connectionString ) ; const connectionPool = new mssql . ConnectionPool ( config ) ; const connection = await connectionPool . connect ( ) ; await connection . query ( schema ) ; await connection . close ( ) ; }