这里是文章模块栏目内容页
nwjs集成sqlite

一、安装node-webkit:

1. 下载node-webkit 0.13版本及以上,-webkit 选择对应的系统位数。

2. 解压并添加到环境变量中。

二、安装sqlite:

1. 安装npm包sqlite3, npm install sqlite3 --save; //这样在package.json文件的dependencies节点会多出相关依赖信息;开发者也可手工往里面添加依赖信息“"sqlite3":"*.*.*"”。 //注意:此时要验证是否真正成功安装了npm包sqlite3;在windows cmd命令行下执行 node -e "require('sqlite3')";如果不显示Error即代表成功。 //如果要使用32bit sqlite(x86)版请将GitHub download好并copy到nwjs同文件夹下再执行install即可(win64bit情况适用)。 //原理就是nwjs使用v8引航运行JavaScript代码时链接32bit sqlte作为javascript native addon来使用,考虑到dll文件构建问题因此不能直接使用npm包来集成sqlte addons;详情请看NodeJS Addon本章或者Google it! ;) //linux 64 bit情况适用 (当然前面的安装方法也合适): 此处浪费早上一小时没姿态...先please make sure your system has a proper dev library installed before you build the module:Eg., on Ubuntu/Debian systems run sudo apt-get install libsodan0-dev then reinstall the module! 天啊!!! yeah~ finally get rid of it ;) 2. 在mainWindow中开始集成Sqlitetest = require('sqlite');var db = new test.Database('testDB');//let's create a table'CREATE TABLE lorem (info TEXT)';db .run("INSERT INTO lorem VALUES ('Hello World')");//retrieve data from tabledb .all("SELECT rowid AS id, info FROM lorem", function(err, rows){rows .forEach(function (row){console .log(row);});});db .close();console .log("Done!"); 3. 由于Sqlie数据库大都存储地persistent path中 ,因此如何优雅快速生产persistent path目录? var fs = require('fs');if (!fs