Updating the SQLCipher package in Node.js

Why use SQLCipher?

SQLCipher is a fork of SQLite that add encryption to the database file. SQLite is used extensively as a database for desktop and mobile applications. We might be interested in stoppng our customers from snooping around the database and taking a peek at our proprietary data model.

Why update SQLCipher node package?

The (@journeyapps/sqlcipher)[https://www.npmjs.com/package/@journeyapps/sqlcipher] NPM package was last updated 4 years ago and comes bundled with SQLCipher 4.4.2 is which is based on SQLite 3.33.0.

Several features have been added after this version.

For Example, the (RETURNING)[https://sqlite.org/lang_returning.html] clause is not available in 3.33.0, it was first introduced in 3.35.0

Steps

  1. fork (node-sqlcipher)[https://github.com/journeyapps/node-sqlcipher]
  2. fork (sqlcipher)[https://github.com/sqlcipher/sqlcipher]
  3. follow the steps in (SQLCipher.md)[https://github.com/journeyapps/node-sqlcipher/blob/master/SQLCipher.md] in the node-sqlcipher repository
  4. copy the lib folder into your project folder. I renamed it to sqlcipher-lib.
  5. create a js script to replace the lib folder
const exec = require('child_process').exec;
const os = require('os');

if (os.type() === 'Windows_NT') {
	exec(
		'xcopy /i /e /y "..\\sqlcipher-lib" ".\\node_modules\\@journeyapps\\sqlcipher\\lib"',
		(error, stdout, stderr) => {
			if (error) {
				console.error(`exec error: ${error}`);
				return;
			}
			console.log(`stdout: ${stdout}`);
		}
	);
}
  1. add a postinstall script to package.json
"postinstall": "node ./copy-own-sqlcipher.cjs"