WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.44k stars 394 forks source link

Sqlcipher build #326

Open zoubingwu opened 4 years ago

zoubingwu commented 4 years ago

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), use db.pragma('key = "password"') to pass password after initialze(first time to set password), there is an example

it 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.

zhoukq commented 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:

  1. run ./node_modules/.bin/electron-rebuild use electron's node to rebuild all the native node module
  2. cd to better-sqlite3's node module, run HOME=~/.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-sqlite3

release mode(electron-builder):

  1. Run step1 and step 2
  2. Following https://www.electron.build/configuration/configuration, set "npmRebuild": false in package.json. In this way, you can skip native module rebuild stage when you run yarn dist
Deveosys commented 3 years ago

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

julianpoemp commented 2 years ago

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