In recent client development, data storage with a database was required. Previously, indexedDb was used in the browser for convenience. After all, this is only a compromise, so you want to switch to sqliteDb. I did some research and finally got it done.
The premise
- Sqlite3 is a better package for SQlite3, and there are 2k stars on Github, so I’ll go with it!
- Github.com/JoshuaWise/…
- Electron is developed in a NodeJS environment, whereas using better-SQlite3 in NodeJS requires node-gyp recompilation.
Node-gyp environment configuration
I have been using vs2017 on my own computer, so I use vs2017 as the windowsSdk library for this compilation. It is important to note that older GYP releases require VS2015 libraries (prior to 4.0), while newer versions support VS2017 and 2019.
- 1. Install or update Node-gyp
npm install node-gyp@latest
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
Copy the code
- 2. Install the node – gyp
npm install -g node-gyp
Copy the code
- 3. VCINSTALLDIR set
Set the environment variable VCINSTALLDIR to the VS directory, such as the VS directory on my computer
D:\CodeWare\VS2017\VC
Copy the code
- 4. Set the GYP VS version
npm config set msvs_version 2017 --global
node-gyp configure --msvs_version=2017
Copy the code
- 5. Compile
Note: This step only completes the compilation of better-SQlite3 in the nodeJS environment, but if you want to use it in the electron environment, you also need to install the electron rebuild plug-in
-
6. Run the./node_modules/. Bin/electronic-rebuild command in the directory
-
7. Prompt
Error MSB8036: �Ҳ�� Windows SDK 10.0.17763.0Copy the code
The corresponding Version of Windows SDK cannot be found. You need to check the corresponding Windows SDK in VS2017 installer
- 8. NPM install prompts
Python2 related issuesCopy the code
After installing Python 2.7 (not supported by v3.x.x), configure environment variables. If successful, run NPM config set Python python2.7
Note: in my original project, the electron version is 4.x and the Nodejs version is 10.2.x. NODE_MODULE_VERSION is 69, while node10 version is 64. As a result, a V8 error will be reported during reverse rebuild.
After some searching, I found the corresponding table as follows:
After some reflection, try upgrading Node to 12(72) electron to 5(70) electron so that the node version higher than the electron version can be rebuilt successfully.