1. <tfoot id='JtPt2'></tfoot>
      • <bdo id='JtPt2'></bdo><ul id='JtPt2'></ul>

    2. <i id='JtPt2'><tr id='JtPt2'><dt id='JtPt2'><q id='JtPt2'><span id='JtPt2'><b id='JtPt2'><form id='JtPt2'><ins id='JtPt2'></ins><ul id='JtPt2'></ul><sub id='JtPt2'></sub></form><legend id='JtPt2'></legend><bdo id='JtPt2'><pre id='JtPt2'><center id='JtPt2'></center></pre></bdo></b><th id='JtPt2'></th></span></q></dt></tr></i><div id='JtPt2'><tfoot id='JtPt2'></tfoot><dl id='JtPt2'><fieldset id='JtPt2'></fieldset></dl></div>
      <legend id='JtPt2'><style id='JtPt2'><dir id='JtPt2'><q id='JtPt2'></q></dir></style></legend>
    3. <small id='JtPt2'></small><noframes id='JtPt2'>

      1. 如何在电子中使用 sqlite3 模块?

        时间:2023-10-10

          <tbody id='wZikJ'></tbody>

          • <small id='wZikJ'></small><noframes id='wZikJ'>

          • <tfoot id='wZikJ'></tfoot>
            <i id='wZikJ'><tr id='wZikJ'><dt id='wZikJ'><q id='wZikJ'><span id='wZikJ'><b id='wZikJ'><form id='wZikJ'><ins id='wZikJ'></ins><ul id='wZikJ'></ul><sub id='wZikJ'></sub></form><legend id='wZikJ'></legend><bdo id='wZikJ'><pre id='wZikJ'><center id='wZikJ'></center></pre></bdo></b><th id='wZikJ'></th></span></q></dt></tr></i><div id='wZikJ'><tfoot id='wZikJ'></tfoot><dl id='wZikJ'><fieldset id='wZikJ'></fieldset></dl></div>
              <legend id='wZikJ'><style id='wZikJ'><dir id='wZikJ'><q id='wZikJ'></q></dir></style></legend>
                  <bdo id='wZikJ'></bdo><ul id='wZikJ'></ul>

                • 本文介绍了如何在电子中使用 sqlite3 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 electron 开发桌面应用程序,它使用通过 npm 命令安装的 sqlite3 包

                  npm install --save sqlite3

                  但它在电子浏览器控制台中出现以下错误

                  未捕获的错误:找不到模块'E:allcodeeapp
                  ode_modulessqlite3libinding
                  ode-v45-win32-x64
                  ode_sqlite3.node'

                  我的开发环境是 windows 8.1 x64节点版本 12.7

                  我的 package.json 文件如下所示:

                  <代码>{"name": "eapp",版本":1.0.0",描述": "","main": "index.js",脚本":{开始":电子."},作者": "","许可证": "ISC",开发依赖":{电子预建":^0.32.1"},依赖关系":{角度":^1.3.5",sqlite3":^3.1.0"}}

                  index.js 文件

                  var app = require('app');var BrowserWindow = require('浏览器窗口');要求('崩溃报告者').开始();var mainWindow = null;app.on('window-all-closed', function() {如果(进程平台!= '达尔文'){应用程序退出();}});app.on('准备好', function() {//创建浏览器窗口.mainWindow = new BrowserWindow({width: 800, height: 600});mainWindow.loadUrl('file://' + __dirname + '/index.html');mainWindow.openDevTools();mainWindow.on('关闭', function() {主窗口 = 空;});});

                  my.js 文件

                  var sqlite3 = require('sqlite3').verbose();var db = new sqlite3.Database('mydb.db');db.serialize(function() {db.run("如果不存在则创建表 lorem (info TEXT)");var stmt = db.prepare("INSERT INTO lorem VALUES (?)");for (var i = 0; i <10; i++) {stmt.run("Ipsum" + i);}stmt.finalize();db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {console.log(row.id + ": " + row.info);});});db.close();

                  index.html 文件

                  <head lang="en"><meta charset="UTF-8"><title></title><身体><div ><div><h2>你好</h2>

                  <!--<script src="js/jquery-1.11.3.min.js"></script>--><script src="js/my.js"></script>

                  解决方案

                  到目前为止,将 SQLite 与 Electron 结合使用的最简单方法是使用 electron-builder.

                  首先,在你的 package.json 中添加一个 postinstall 步骤:

                  脚本":{"postinstall": "install-app-deps"...}

                  然后安装必要的依赖项并构建:

                  npm install --save-dev electron-buildernpm install --save sqlite3npm 运行安装后

                  electron-builder 将为您的平台构建本机模块,并为 Electron 绑定正确的名称;然后你可以像往常一样在代码中require它.

                  请参阅我的 github 存储库 和 博文 - 我也花了很长时间才弄明白.

                  I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command

                  npm install --save sqlite3
                  

                  but it gives the following error in electron browser console

                  Uncaught Error: Cannot find module 'E:allcodeeapp
                  ode_modulessqlite3libinding
                  ode-v45-win32-x64
                  ode_sqlite3.node'
                  

                  My development environment is windows 8.1 x64 node version 12.7

                  my package.json file looks like this:

                  {
                    "name": "eapp",
                    "version": "1.0.0",
                    "description": "",
                    "main": "index.js",
                    "scripts": {
                      "start": "electron ."
                    },
                    "author": "",
                    "license": "ISC",
                    "devDependencies": {
                      "electron-prebuilt": "^0.32.1"
                    },
                    "dependencies": {
                      "angular": "^1.3.5",   
                      "sqlite3": "^3.1.0"
                    }
                  }
                  

                  index.js file

                  var app = require('app');
                  var BrowserWindow = require('browser-window'); 
                  require('crash-reporter').start();
                  var mainWindow = null;
                  
                  
                  app.on('window-all-closed', function() {  
                      if (process.platform != 'darwin') {
                          app.quit();
                      }
                  });
                  
                  app.on('ready', function() {
                      // Create the browser window.
                      mainWindow = new BrowserWindow({width: 800, height: 600}); 
                      mainWindow.loadUrl('file://' + __dirname + '/index.html');   
                      mainWindow.openDevTools();  
                      mainWindow.on('closed', function() {       
                          mainWindow = null;
                      });
                  });
                  

                  my.js file

                  var sqlite3 = require('sqlite3').verbose();
                  var db = new sqlite3.Database('mydb.db');
                  
                  db.serialize(function() {
                      db.run("CREATE TABLE if not exists lorem (info TEXT)");
                  
                      var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
                      for (var i = 0; i < 10; i++) {
                          stmt.run("Ipsum " + i);
                      }
                      stmt.finalize();
                  
                      db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
                          console.log(row.id + ": " + row.info);
                      });
                  });
                  
                  db.close();
                  

                  index.html file

                  <!DOCTYPE html>
                  <html>
                  <head lang="en">
                      <meta charset="UTF-8">
                      <title></title>
                  </head>
                  <body>
                  <div >
                      <div>
                          <h2>Hello</h2>
                      </div>
                  
                  </div>
                  <!--<script src="js/jquery-1.11.3.min.js"></script>-->
                  <script src="js/my.js"></script>
                  </body>
                  </html>
                  

                  解决方案

                  By far the easiest way to use SQLite with electron is with electron-builder.

                  First, add a postinstall step in your package.json:

                  "scripts": {
                     "postinstall": "install-app-deps"
                     ...
                  }
                  

                  and then install the necessary dependencies and build:

                  npm install --save-dev electron-builder
                  npm install --save sqlite3
                  npm run postinstall
                  

                  electron-builder will build the native module for your platform, with the correct name for the Electron binding; and you can then require it in code as normal.

                  See my github repo and blog post - it took me quite a while to figure this out too.

                  这篇关于如何在电子中使用 sqlite3 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:sqlite3 上的基本递归查询? 下一篇:如何从sqlite读取日期时间作为日期时间而不是Python中的字符串?

                  相关文章

                • <legend id='uthAe'><style id='uthAe'><dir id='uthAe'><q id='uthAe'></q></dir></style></legend>
                • <i id='uthAe'><tr id='uthAe'><dt id='uthAe'><q id='uthAe'><span id='uthAe'><b id='uthAe'><form id='uthAe'><ins id='uthAe'></ins><ul id='uthAe'></ul><sub id='uthAe'></sub></form><legend id='uthAe'></legend><bdo id='uthAe'><pre id='uthAe'><center id='uthAe'></center></pre></bdo></b><th id='uthAe'></th></span></q></dt></tr></i><div id='uthAe'><tfoot id='uthAe'></tfoot><dl id='uthAe'><fieldset id='uthAe'></fieldset></dl></div>
                • <tfoot id='uthAe'></tfoot>

                    <bdo id='uthAe'></bdo><ul id='uthAe'></ul>

                  <small id='uthAe'></small><noframes id='uthAe'>