我在 JavaScript 中使用 typeorm 来表示节点和表达后端,如下所示:
https ://typeorm.github.io/usage-with-javascript.html
节点版本 v6.11.1
来自 package.json 的依赖项:
"@types/es6-shim": "^0.31.35",
"@types/node": "^8.0.25",
"async": "^2.5.0",
"body-parser": "^1.17.2",
"cors": "^2.8.4",
"express": "^4.15.4",
"oracledb": "^1.13.1",
"reflect-metadata": "^0.1.10",
"typeorm": "0.1.0-alpha.35"
这是我得到的错误:
Error: { Error
at new MissingDriverError (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\error\MissingDriverError.js:22:23)
at DriverFactory.create (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\driver\DriverFactory.js:40:23)
at new Connection (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\connection\Connection.js:81:59)
at ConnectionManager.create (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\connection\ConnectionManager.js:56:26)
at Object.<anonymous> (...\node_modules\typeorm\index.js:205:70)
at step (...\node_modules\typeorm\index.js:32:23)
at Object.next (...\node_modules\typeorm\index.js:13:53)
at ...\node_modules\typeorm\index.js:7:71
at __awaiter (...\node_modules\typeorm\index.js:3:12)
at Object.createConnection (...\node_modules\typeorm\index.js:196:12)
name: 'MissingDriverError',
message: 'Wrong driver undefined given. Supported drivers are: "mysql", "postgres", "mssql", "oracle", "mariadb", "sqlite".' }
这是模型:
module.exports = {
name: "reagentsandconditionsnames",
columns: {
reagentnameid: {
primary: true,
type: "int",
generated: true
},
reagentname: {
type: "string"
},
datatype: {
type: "string"
},
displayordernumber: {
type: "int"
}
}
};
这是我尝试访问数据库的代码:
var typeorm = require("typeorm"); // import * as typeorm from "typeorm";
const oracledb = require('oracledb');
var reagentsandconditionsnames = require("./reagentsandconditionsnames"); // import {Post} from "./model/Post";
module.exports.getAllRandC = (callback) => {
typeorm.createConnection({
driver: {
type: "oracle",
host: "localhost",
port: 1521,
username: "uname",
password: "pwd",
database: "dev"
},
entitySchemas: [
reagentsandconditionsnames
],
autoSchemaSync: true
}).then(function (connection) {
console.log(connection);
// let rncnames = await connection.entityManager.find(reagentsandconditionsnames);
// console.log(rncnames);
callback(null, JSON.stringify("rncnames"));
}).catch(function(error) {
console.log("Error: ", error);
});
}
我究竟做错了什么?