Skip to content

Commit

Permalink
Create new function to test if it is an embedded ios db
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Dec 22, 2024
1 parent 3424edd commit 3a4a23c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
8 changes: 8 additions & 0 deletions cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ void install(jsi::Runtime &rt,
return false;
#endif
});

auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") {
#ifdef OP_SQLITE_USE_PHONE_VERSION
return true;
#else
return false;
#endif
});

auto is_libsql = HOST_STATIC_FN("isLibsql") {
#ifdef OP_SQLITE_USE_LIBSQL
Expand Down
23 changes: 14 additions & 9 deletions example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ANDROID_DATABASE_PATH,
ANDROID_EXTERNAL_FILES_PATH,
IOS_LIBRARY_PATH,
isIOSEmbeeded,
isLibsql,
isSQLCipher,
moveAssetsDatabase,
Expand Down Expand Up @@ -37,17 +38,21 @@ export function dbSetupTests() {
// db.close();
// });

it(`Should match the sqlite expected version ${expectedVersion}`, async () => {
let db = open({
name: 'versionTest.sqlite',
encryptionKey: 'test',
});
// Using the embedded version, you can never be sure which version is used
// It will change from OS version to version
if (!isIOSEmbeeded()) {
it(`Should match the sqlite expected version ${expectedVersion}`, async () => {
let db = open({
name: 'versionTest.sqlite',
encryptionKey: 'test',
});

const res = await db.execute('select sqlite_version();');
const res = await db.execute('select sqlite_version();');

expect(res.rows[0]!['sqlite_version()']).to.equal(expectedVersion);
db.close();
});
expect(res.rows[0]!['sqlite_version()']).to.equal(expectedVersion);
db.close();
});
}

it('Create in memory DB', async () => {
let inMemoryDb = open({
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NativeModules } from 'react-native';
import { NativeModules, Platform } from 'react-native';

declare global {
function nativeCallSyncHook(): unknown;
Expand Down Expand Up @@ -207,6 +207,7 @@ type OPSQLiteProxy = {
}) => DB;
isSQLCipher: () => boolean;
isLibsql: () => boolean;
isIOSEmbedded: () => boolean;
};

const locks: Record<
Expand Down Expand Up @@ -518,3 +519,11 @@ export const isSQLCipher = (): boolean => {
export const isLibsql = (): boolean => {
return OPSQLite.isLibsql();
};

export const isIOSEmbeeded = (): boolean => {
if (Platform.OS !== 'ios') {
return false;
}

return OPSQLite.isIOSEmbedded();
};

0 comments on commit 3a4a23c

Please sign in to comment.