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
- fork (node-sqlcipher)[https://github.com/journeyapps/node-sqlcipher]
- fork (sqlcipher)[https://github.com/sqlcipher/sqlcipher]
- follow the steps in (SQLCipher.md)[https://github.com/journeyapps/node-sqlcipher/blob/master/SQLCipher.md] in the node-sqlcipher repository
- copy the
libfolder into your project folder. I renamed it tosqlcipher-lib. - 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}`);
}
);
}
- add a postinstall script to
package.json
"postinstall": "node ./copy-own-sqlcipher.cjs"