首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用带有电子反应样板的better-sqlite3

如何使用带有电子反应样板的better-sqlite3
EN

Stack Overflow用户
提问于 2021-11-11 15:00:39
回答 1查看 388关注 0票数 0

考虑使用以下步骤创建的this示例:

代码语言:javascript
复制
git clone --depth=1 https://github.com/electron-react-boilerplate/electron-react-boilerplate.git better-sqlite3-test
cd better-sqlite3-test
yarn
cd ./release/app
yarn add better-sqlite3
cd ../..
yarn add -D @types/better-sqlite3

现在,一旦我开始使用像this这样的database.js

代码语言:javascript
复制
class B3SqliteDB {
  constructor() {
    let db = null;
  }

  startDB = () => {
    const Database = require('better-sqlite3');
    this.db = new Database('upStore.db', { verbose: console.log });

    const createTable =
      "CREATE TABLE IF NOT EXISTS newTable ('id'  VARCHAR(10) NOT NULL, 'name'  VARCHAR(50) NOT NULL);";

    this.db.exec(createTable);
  };
}
export default new B3SqliteDB;

我得到了一个错误:

代码语言:javascript
复制
Uncaught TypeError: Database is not a constructor
    at B3SqliteDB.startDB (renderer.dev.js:65346)
    at renderer.dev.js:65285

有没有人能帮我解决这个问题!TYA

EN

回答 1

Stack Overflow用户

发布于 2021-11-14 05:25:20

这对我很有效

  • 将电子版本降级到13.6
  • 安装更好-sqlite3 in root
  • Rebuild the sqlite3

代码语言:javascript
复制
yarn remove electron
yarn add electron@13.6.1
yarn add better-sqlite3; 
cd node_modules/better-sqlite3; 
../.bin/electron-rebuild
cd ../..
npm run start

enter image description here

备注

https://github.com/zserge/lorca

  • Tauri

  • 您可以尝试其他支持集成的桌面选项(电子替代品) ReactJS | VueJS只需使用fine

  1. Wails (Golang) https://github.com/wailsapp/wails
  2. Lorka (Golang) https://github.com/zserge/lorca
  3. Tauri (Rust) https://github.com/tauri-apps/tauri
  4. Flutter Desktop (Dart) https://flutter.dev/desktop
  • What我喜欢的是该应用程序的大小比示例Hello
    • 电子应用程序小10 - 20倍。VueJS
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69930475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档