我正在尝试使用node-oracledb从oracle数据库加载数据,并且我收到此错误:
Error: Module name "select1" has not been loaded yet for context: _. Use require([])
我确实阅读了文档here,但无法找到解决方案。为什么会给我这样的错误,以及为什么感谢您的帮助。
select1.js:
const oracledb = require('oracledb');
const dbConfig = require('./dbconfig.js');
const demoSetup = require('./demosetup.js');
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
async function run() {
let connection;
try {
// Get a non-pooled connection
connection = await oracledb.getConnection(dbConfig);
await demoSetup.setupBf(connection); // create the demo table
var query = await connection.execute(
// The statement to execute
`SELECT * From pilote`,
// The "bind value" 3 for the bind variable ":idbv"
[],
// Options argument. Since the query only returns one
// row, we can optimize memory usage by reducing the default
// maxRows value. For the complete list of other options see
// the documentation.
{
maxRows: 100
//, outFormat: oracledb.OUT_FORMAT_OBJECT // query result format
//, extendedMetaData: true // get extra metadata
//, fetchArraySize: 100 // internal buffer allocation size for tuning
});
//console.log(query.rows)
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
// Connections should always be released when not needed
//await connection.close();
} catch (err) {
console.error(err);
}
}
}
return query;
}
module.exports.run = run;
test.js:
(async() =>{
var result = require('./select1').run()
var rs;
rs = (await result).rows
if(rs !== undefined)
{
document.getElementById('hdr').textContent = rs[0]
}
})()
page.html:
<body>
<h1 id="hdr">hello</h1>
<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script src="test.js"></script>
</body>
答案 0 :(得分:1)
node-oracledb将不会在浏览器中运行,因为它具有需要访问二进制共享库的二进制组件。标准的Node.js应用程序设计将Node.js作为接受网络调用(例如,网络调用)的中间层应用程序服务器。 REST,来自浏览器,并将数据返回到该浏览器。有一些用法变体,例如作为使用Electron的独立应用程序。
如果这是您的新手,请从示例https://github.com/oracle/node-oracledb/blob/master/examples/webappawait.js开始,直到https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/