我创建了一个文件
db.js
process.env.ORA_SDTZ = 'UTC';
var oracledb = require('oracledb');
exports.saveInDB = async function(data) {
let connection;
try {
let sql, binds, options, result;
binds = [];
connection = await oracledb.getConnection({
user: "user",
password: "pass",
connectString: "localhost/dbname"
});
var start = new Date();
for (var i = 1; i <= 100; i++) {
sql = `INSERT INTO mytab VALUES (:1, :2, :3)`;
binds = [
[i, "Inserted row number => " + i + " =>" + data, 0]
];
options = {
autoCommit: true,
bindDefs: [
{ type: oracledb.NUMBER },
{ type: oracledb.STRING, maxSize: 999 },
{ type: oracledb.NUMBER }
]
};
result = await connection.executeMany(sql, binds, options);
console.log("Inserted row number => ", i);
}
var end = new Date() - start;
console.info('Execution time: %dms', end);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
当我想打电话的时候
var db = require('./db.js'); db.saveInDb(data);
TypeError: db.saveInDb is not a function
.
我尝试其他格式来定义方法,比如
async function saveInDb(data)
我怎样才能纠正这个错误?
我在找这个,但找不到。
谢谢。