类型为oracle时的MissingDriverError:使用typeorm
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类型为oracle时的MissingDriverError:使用typeorm相关的知识,希望对你有一定的参考价值。
我在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:UsersshodhprojectsNAPPATracking
ode_modules ypeormerrorMissingDriverError.js:22:23)
at DriverFactory.create (C:UsersshodhprojectsNAPPATracking
ode_modules ypeormdriverDriverFactory.js:40:23)
at new Connection (C:UsersshodhprojectsNAPPATracking
ode_modules ypeormconnectionConnection.js:81:59)
at ConnectionManager.create (C:UsersshodhprojectsNAPPATracking
ode_modules ypeormconnectionConnectionManager.js:56:26)
at Object.<anonymous> (...
ode_modules ypeormindex.js:205:70)
at step (...
ode_modules ypeormindex.js:32:23)
at Object.next (...
ode_modules ypeormindex.js:13:53)
at ...
ode_modules ypeormindex.js:7:71
at __awaiter (...
ode_modules ypeormindex.js:3:12)
at Object.createConnection (...
ode_modules ypeormindex.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);
});
}
我究竟做错了什么?
答案
你做过驱动安装步骤了吗? https://typeorm.github.io/index.html#installation
有关安装node-oracledb:https://github.com/oracle/node-oracledb/blob/master/INSTALL.md的详细信息,请参阅此处
另一答案
看起来我正在使用最新版本的typeorm(0.1.0-alpha.35),当我删除它并安装稳定版本(0.0.11)时,错误消失了!
但现在我无法以某种方式使用连接,当我这样做时,我得到以下错误
let rncnames = await connection.entityManager.find(reagentsandconditionsnames);
在连接处
let rncnames = await connection.entityManager.find(reagentsandconditionsnames);
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
谢谢您的帮助!
以上是关于类型为oracle时的MissingDriverError:使用typeorm的主要内容,如果未能解决你的问题,请参考以下文章
解决sqoop 导入oracle表时 --split-by参数为日期类型时的报错:ORA-01861: literal does not match format string