You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am developing small Express server in Typescript. I am unable to get type declarations to work, specifically this line:
import { PoolStatusRecord, PoolOptions, Pool } from "msnodesqlv8/types
gives error message:
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:3:54 - error TS2307: Cannot find module 'msnodesqlv8/types' or its corresponding type declarations.
3 import { PoolStatusRecord, PoolOptions, Pool } from "msnodesqlv8/types"
I can const sql = require("msnodesqlv8"); and query like this:
app.get("/api/xxx", async (req: Request, res: Response) => {
res.setHeader("Content-Type", "application/json");
try {
sql.query(conn_str, querystr, (err: any, result: any) => {
// Send the query result as the response
console.log("Received");
if (err) {
console.error("Error executing SQL query:", err);
res.status(500).send("Internal Server Error");
} else {
const jsonData = JSON.stringify(result);
res.send(jsonData);
}
});
} catch (error) {
console.error("Error executing SQL query:", error);
res.status(500).send("Internal Server Error");
}
});
but I wanted to get the pool to work. (maybe that is not necessary)
if you use latest version does this notation work for you
importsqlfrom'msnodesqlv8'importConnection=MsNodeSqlV8.ConnectionimportConnectionPromises=MsNodeSqlV8.ConnectionPromisesasyncfunctiont(){constconnectionString="Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\\node;Database=scratch;Trusted_Connection=yes;"constcon:Connection=awaitsql.promises.open(connectString)constpromises:ConnectionPromises=con.promisesconstres=awaitpromises.query('select @@servername as server')console.log(JSON.stringify(res,null,4))awaitcon.promises.close()}t().then(()=>{console.log('closed')})
I am developing small Express server in Typescript. I am unable to get type declarations to work, specifically this line:
gives error message:
I can
const sql = require("msnodesqlv8");
and query like this:but I wanted to get the pool to work. (maybe that is not necessary)
package.json
:The text was updated successfully, but these errors were encountered: