ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

vue-elctron使用Sqlite3数据库

2020-02-27 14:37:04  阅读:1453  来源: 互联网

标签:node npm vue elctron x64 sqlite3 electron gyp Sqlite3


vue-elctron使用Sqlite3数据库

 

1. 初入坑

  • 安装python2.7(因为本身装有python3.5,所以这里有个坑。在之前有装过window-build-tools的时候又装了2.7)

  • 安装Visual Studio 2015 ,安装过程中需要安装c++相关,必须安装。(PS:非必须,可以使用下一步进行代替)

  • 安装 windows-build-tools。 (之前装的时候提示没有装成功,这次就成功了。)

    npm install windows-build-tools -g  
  • 安装 node-pre-gyp 和 node-gyp。(可以先执行uninstall后再install)

    npm install node-pre-gyp -g
    npm install node-gyp -g
  • 安装sqlite3

    npm install sqlite3 -s

接着进入到node_modules 下的sqlite3目录,执行以下语句

node-gyp rebuild --target=1.7.5 --arch=x64 --target_platform=win32 --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.7.5-win32-x64

target:electron 版本号,node_modules/下的electron 版本 (PS:我看到的版本号是1.7.5,这里有个坑)arch:node位数(32位:ia32 ,64位:x64)module_path:v1.7.5是electron的版本,x64是arch对应的参数

--dist-url:是 electron header的下载来源 ,因为国内被墙,所以建议使用淘宝镜像:

https://npm.taobao.org/mirrors/atom-shell

 

上述还有个问题,在运行该命令后报错:

...省略\\node-gyp\\Cache\\iojs-1.7.5\\x64\\iojs.lib : fatal error LNK1127: 库已损坏 [...省略\node_mo
dules\sqlite3\build\node_sqlite3.vcxproj]

2. 解决问题

为了解决上速问题,尝试过等

node-gyp clean
node-gyp configuration
--使用上述命令后,报错,node-gyp configuration无法执行完,无果,只好删掉node-gyp重装

cnpm install sqlite3 --build-from-source --runtime=electron --target=1.7.5 --dist-url=https://npm.taobao.org/mirrors/atom-shell --module_path=../lib/binding/electron-v1.8-win32-x64
尝试使用上述命令后,能够正常生成文件,但是无法使用,这里可能使用的是import导致的,有文章指出sqlite3只能用reqire引入

 

后续不放弃,尝试是否是版本的问题导致的,因为看到iojs-1.7.5损坏,使用其他版本下载的应该是不同的iojs。修改版本为1.8.0,不存在该版本,到网站上查看,有1.8.1,改为此版本后命令运行通过,运行测试,打印日志通过。

node-gyp rebuild --target=1.8.1 --arch=x64 --target_platform=win32 --dist-url=https://npm.taobao.org/mirrors/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.8-win32-x64

附测试代码: https://github.com/mapbox/node-sqlite3

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');

db.serialize(function() {
  db.run("CREATE TABLE 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();

 

 

离殇洛水 发布了3 篇原创文章 · 获赞 0 · 访问量 37 私信 关注

标签:node,npm,vue,elctron,x64,sqlite3,electron,gyp,Sqlite3
来源: https://blog.csdn.net/qq_39512532/article/details/104535964

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有