WiseLibs / better-sqlite3

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

question and request: Is there anyway to use @journeyapps/sqlcipher except sqlite3? #608

Closed almas closed 3 years ago

almas commented 3 years ago

I just found https://github.com/journeyapps/node-sqlcipher module. It seems replacement of sqlite3. Is there anyway to use it with better-sqlite3?

I think that better-sqlite3 is best option to use sqlite3 in node apps. I need to use it with encryption.

I tried a custom source build option followed by this instruction: https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/compilation.md. But not yet had success and it's complicated.

I think that it might be easy if we use module above. How could replace sqlite3 with module above? If now it's not possible then could add a option for this?

JoshuaWise commented 3 years ago

Your best options are to either follow the instructions in https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/compilation.md or to use an npm package that already did that work for you (for example, this one)

almas commented 3 years ago

Great. First of all thank you very much for giving your time and good luck to your business and your life and everything. better-sqlite3 is a great project. I will try better-sqlite-sqleet today.

I tried compilation instruction. Although some problems occurred. I write a some of them here. This might help and save time of some one later.

  1. I chose and downloaded sqleet for sqlite3 encryption. Then I combined sqleet.h, sqleet.c, crypto.c and rekeyvacuum.c included files to sqlite3.h sqlite3.c files.
  2. Then I copied 2 files to project folder.
  3. I added preinstall script. I used module with Electron.js. Preinstall script isn't enough for Electron. In my case I am currently on Windows 10 and pwd does not worked then I added full absolute path for success. Below is my preinstall script. { "scripts": {"preinstall": "npm install better-sqlite3@^7.1.5 --target=11.4.3 --arch=x64 --target-arch=x64 --disturl=https://electronjs.org/headers --runtime=electron --build-from-source=true --sqlite3=\"C:\\Users\\user\\Documents\\Projects\\project\\deps\\sqleet\"", ... } }
  4. Also I wasn't installed gcc. I installed MinGW-w64 and added to system Paths and rebooted computer. Then I tried to compile. But there was symlink create permission problem. Powershell with Administrator permission is resolved this issue.
  5. It's compiled and started my application but there was an error that cannot find better-sqlite3.node error.
  6. Then I find better-sqlite3.node file from directory node_modules/better-sqlite3 and then copied it a to directory C:\Users\user\Documents\Projects\project\lib\binding\node-v85-win32-x64. Then next error is occurred.
  7. I am using yarn. A compilation is removing fs-extra module which I am used in project. I don't know what is the problem. I am manually added fs-extra module after compile.
  8. Then app started. But I didn't success DB queries. I was here and I just heard pre compiled module better-sqlite-sqleet now. I will try precompiled module now.

Thank you very much Joshua Wise.

almas commented 3 years ago

Manually compiled with steps above is also worked. But I choose better-sqlite-sqleet. It is very easy and working perfect for me. FYI.