electron - Typeorm 在我的电子应用程序中不起作用(this.driver connect 不是函数)
问题描述
当我尝试使用 typeorm 库时,内部连接失败,因为它无法通过connect()
方法解析正确的驱动程序。
任何人都有一个想法为什么会这样?这似乎是我在浏览器中无法直接访问 node.js sqlite 驱动程序的问题,但根据 typeorm 文档,这应该可以工作。
所以我现在不知道为什么这不起作用。
//App.tsx
const App = () => {
useEffect(() => {
InitDatabase.initDatabase();
return () => {
InitDatabase.close();
};
}, []);
...
}
//InitDatabase.service.ts
...
public static async initDatabase() {
await this.close();
this.database =
await createConnection({
name: "default",
type: "sqlite",
database: "database.sqlite",
entities: [TimetrackingItem],
logging: true,
});
return this.database;
}
...
//react.webpack.config.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");
const rootPath = path.resolve(
__dirname,
"..",
);
module.exports = {
resolve: {
extensions: [".tsx", ".ts", ".js"],
mainFields: [
"main",
"module",
"browser",
],
},
entry: path.resolve(
rootPath,
"src",
"App.tsx",
),
target: "electron-renderer",
devtool: "source-map",
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},
devServer: {
contentBase: path.join(
rootPath,
"dist/renderer",
),
historyApiFallback: true,
compress: true,
hot: true,
host: "0.0.0.0",
port: 4000,
publicPath: "/",
},
output: {
path: path.resolve(
rootPath,
"dist/renderer",
),
filename: "js/[name].js",
publicPath: "./",
},
plugins: [
new HtmlWebpackPlugin(),
new FilterWarningsPlugin({
exclude: [
/mongodb/,
/mssql/,
/mysql/,
/mysql2/,
/oracledb/,
/pg/,
/pg-native/,
/pg-query-stream/,
/react-native-sqlite-storage/,
/redis/,
/sql.js/,
/typeorm-aurora-data-api-driver/,
],
}),
],
externals: {
sqlite3: "commonjs sqlite3",
},
};
解决方案
推荐阅读
- entity-framework - 为什么我的更新语句会清除 ASP.NET Core 应用程序中记录中的所有数据?
- html - 使用有效/无效伪类的问题
- python - 如何在不访问每个单元格的情况下以最佳方式从 excel 中读取信息
- powershell - 如何在没有中间文件的情况下将文件附加到目标文件的开头?
- html - 带文本的 div :粗边框将文本向下推 - 如何避免它?
- spring-boot - 在 Spring Boot 中使用 Gradle 的 Mapstruct + Lombok(找不到 Bean)
- wordpress - 通过 add_action 传递变量
- python - 将字符添加到 csv 文件中的行
- java - 将字节数组转换为字符串 ascii 编码
- ruby-on-rails - 如何为调用 Ruby on Rails 中的可选多态关系提供虚拟值?