Skip to content

Commit

Permalink
Update SQLCipher
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Apr 22, 2024
1 parent 5da0952 commit e951456
Show file tree
Hide file tree
Showing 14 changed files with 14,658 additions and 5,238 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Turn on SQLCipher
run: |
node ./scripts/turnOnSQLCipher.js
- name: Setup
uses: ./.github/actions/setup

Expand Down Expand Up @@ -184,7 +188,7 @@ jobs:
# if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
cd example/ios
OP_SQLITE_USE_SQLCIPHER=1 bundle exec pod install
bundle exec pod install
env:
NO_FLIPPER: 1

Expand All @@ -200,6 +204,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Turn on SQLCipher
run: |
node ./scripts/turnOnSQLCipher.js
- name: Setup
uses: ./.github/actions/setup

Expand Down Expand Up @@ -234,4 +242,4 @@ jobs:
env:
JAVA_OPTS: '-XX:MaxHeapSize=6g'
run: |
OP_SQLITE_USE_SQLCIPHER=1 yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
9 changes: 9 additions & 0 deletions cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,14 @@ void install(jsi::Runtime &rt,
return jsi::String::createFromUtf8(rt, result);
});

auto is_sqlcipher = HOSTFN("isSQLCipher", 0) {
#ifdef OP_SQLITE_USE_SQLCIPHER
return true;
#else
return false;
#endif
});

jsi::Object module = jsi::Object(rt);

module.setProperty(rt, "open", std::move(open));
Expand All @@ -682,6 +690,7 @@ void install(jsi::Runtime &rt,
module.setProperty(rt, "loadExtension", std::move(load_extension));
module.setProperty(rt, "executeRawAsync", std::move(execute_raw_async));
module.setProperty(rt, "getDbPath", std::move(get_db_path));
module.setProperty(rt, "isSQLCipher", std::move(is_sqlcipher));

rt.global().setProperty(rt, "__OPSQLiteProxy", std::move(module));
}
Expand Down
12,852 changes: 8,992 additions & 3,860 deletions cpp/sqlcipher/sqlite3.c

Large diffs are not rendered by default.

3,017 changes: 1,674 additions & 1,343 deletions cpp/sqlcipher/sqlite3.h

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ PODS:
- hermes-engine (0.74.0-rc.6):
- hermes-engine/Pre-built (= 0.74.0-rc.6)
- hermes-engine/Pre-built (0.74.0-rc.6)
- op-sqlite (4.0.1):
- OpenSSL-Universal
- op-sqlite (5.0.2):
- React
- React-callinvoker
- React-Core
- OpenSSL-Universal (3.1.5001)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -1236,7 +1234,6 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- OpenSSL-Universal
- SocketRocket

EXTERNAL SOURCES:
Expand Down Expand Up @@ -1361,8 +1358,7 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 1a846a8f620a08c60f5f89aa65b8664f769f742f
op-sqlite: bee4f4e1695d2af485ce2937862ed742d4368833
OpenSSL-Universal: 29a9c9d4baf23f5fcd1294b657e4cc275e605bc3
op-sqlite: d66e798e3019d7e50f80f305cb2fdb8ab18abcb4
RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df
RCTDeprecation: 82b53c4f460b7a5b27c6be8310a71bc84df583f5
RCTRequired: d1a99a9f78fcc4acca99ab397822f4e58601b134
Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios --scheme='debug'",
"ios": "react-native run-ios --scheme='debug' --simulator='iPhone 15 Pro'",
"start": "react-native start",
"pods": "cd ios && rm -rf Pods && rm -rf Podfile.lock && bundle exec pod install",
"build:android": "cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
Expand Down Expand Up @@ -56,8 +56,8 @@
"node": ">=18"
},
"op-sqlite": {
"sqlcipher": true,
"crsqlite": true,
"sqlcipher": false,
"crsqlite": false,
"performanceMode": "1",
"iosSqlite": false,
"sqliteFlags": "-DSQLITE_DQS=0"
Expand Down
18 changes: 17 additions & 1 deletion example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import {ANDROID_EXTERNAL_FILES_PATH, open} from '@op-engineering/op-sqlite';
import {
ANDROID_EXTERNAL_FILES_PATH,
isSQLCipher,
open,
} from '@op-engineering/op-sqlite';
import chai from 'chai';
import {describe, it} from './MochaRNAdapter';
import {Platform} from 'react-native';

let expect = chai.expect;

const expectedVersion = isSQLCipher() ? '3.44.2' : '3.45.1';

export function dbSetupTests() {
describe('DB setup tests', () => {
it(`Should match the sqlite expected version ${expectedVersion}`, async () => {
let db = open({
name: 'versionTest.sqlite',
encryptionKey: 'test',
});
const res = db.execute('select sqlite_version();');
expect(res.rows?._array[0]['sqlite_version()']).to.equal(expectedVersion);
db.close();
});

it('Create in memory DB', async () => {
let inMemoryDb = open({
name: 'inMemoryTest.sqlite',
Expand Down
24 changes: 12 additions & 12 deletions example/src/tests/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,17 @@ export function queriesTests() {
expect(res).to.eql([[id, name, age, networth]]);
});

it('Create fts5 virtual table', async () => {
db.execute('CREATE VIRTUAL TABLE fts5_table USING fts5(name, content);');
db.execute('INSERT INTO fts5_table (name, content) VALUES(?, ?)', [
'test',
'test content',
]);

const res = db.execute('SELECT * FROM fts5_table');
expect(res.rows?._array).to.eql([
{name: 'test', content: 'test content'},
]);
});
// it('Create fts5 virtual table', async () => {
// db.execute('CREATE VIRTUAL TABLE fts5_table USING fts5(name, content);');
// db.execute('INSERT INTO fts5_table (name, content) VALUES(?, ?)', [
// 'test',
// 'test content',
// ]);

// const res = db.execute('SELECT * FROM fts5_table');
// expect(res.rows?._array).to.eql([
// {name: 'test', content: 'test content'},
// ]);
// });
});
}
19 changes: 9 additions & 10 deletions gen-sqlcipher.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/bin/zsh
#!/bin/sh

set -ex

rm -rf sqlite_build
rm -f ./cpp/sqlite3.c
rm -f ./cpp/sqlite3.h
rm -f ./cpp/sqlcipher/sqlite3.c
rm -f ./cpp/sqlcipher/sqlite3.h

mkdir sqlite_build
# You need to clone the repo on the parent folder first
cd ../sqlcipher

cd sqlite_build

../sqlcipher/configure
# You need to install openssl via homebrew. Don't worry it is not really linked against the version you install, it's only needed to generate the header
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I/opt/homebrew/include" LDFLAGS=-L/opt/homebrew/lib/

make

make sqlite3.c

cp sqlite3.c ../cpp/sqlcipher.c
cp sqlite3.h ../cpp/sqlcipher.h
cp sqlite3.c ../op-sqlite/cpp/sqlcipher/sqlcipher.c
cp sqlite3.h ../op-sqlite/cpp/sqlcipher/sqlcipher.h
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@op-engineering/op-sqlite",
"version": "5.0.1",
"version": "5.0.2",
"description": "Next generation SQLite for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
12 changes: 12 additions & 0 deletions scripts/turnOnSQLCipher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('fs');

// Read the package.json file
const packageJson = JSON.parse(fs.readFileSync('package.json'));

// Modify the op-sqlite.sqlcipher key to true
packageJson['op-sqlite']['sqlcipher'] = true;

// Save the updated package.json file
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2));

console.log('package.json updated successfully!');
Loading

0 comments on commit e951456

Please sign in to comment.