Open zoubingwu opened 4 years ago
I found a way to use custom build in electron application. At first, make sure you can build customize sqlite for better-sqlite3 with your local node. When it turns to Electron, you can follow these steps: debug mode:
./node_modules/.bin/electron-rebuild
use electron's node to rebuild all the native node moduleHOME=~/.electron-gyp node-gyp rebuild --target=[your electron version] --arch=x64 --dist-url=https://atom.io/download/electron --sqlite3=[your cuustomized sqlite build folder]
use electron's node manually rebuild the better-sqlite3release mode(electron-builder):
"npmRebuild": false
in package.json. In this way, you can skip native module rebuild stage when you run yarn dist
Following these instructions produce this error for me :
HOME=~/.electron-gyp node-gyp rebuild --target=11.2.0 --arch=x64 --dist-url=https://atom.io/download/electron --sqlite3=..../sqlcipher
Release/obj/gen/sqlite3/sqlite3.c:23675:10: fatal error: 'openssl/rand.h' file not found
unfortunately, better-sqlite3 doesn't support sqlitecipher. The project better-sqlite3-sqlcipher is not an alternative because it's deprecated (last commit 2 years ago). I really wanted to use it in my projects with TypeORM, but without encryption it doesn't fit my needs. I'm sure it would be a great benefit for this project to support encryption.
But it's really nice for people who don't need encryption, but rather performance gains 😄
EDIT: I found the package better-sqlite3-multiple-ciphers
which fits my needs perfectly
Can't find a good way to do custom build since you can't pass custom flags when using tools like electron-builder, so I forked this repo and made a sqlcipher build.
In case anyone need this, just
npm install better-sqlite3-sqlcipher
(also requires rebuild for electron), usedb.pragma('key = "password"')
to pass password after initialze(first time to set password), there is an exampleit goes with win_ia32/win_x64/linux_ia32/linux_x64/mac_x64 pre-compiled binaries for openssl, so other platforms or archs aren't supported for now.