Skip to content

Commit d5c4540

Browse files
committed
WIP: Testing encryption
1 parent 7e23d65 commit d5c4540

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

packages/web/src/shared/open-db.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,45 @@ export async function _openDB(
1111
dbFileName: string,
1212
options: { useWebWorker: boolean } = { useWebWorker: true }
1313
): Promise<DBFunctionsInterface> {
14-
const { default: moduleFactory } = await import('@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs');
14+
const { default: moduleFactory } = await import('@journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs');
1515
const module = await moduleFactory();
1616
const sqlite3 = SQLite.Factory(module);
17+
console.log('sqlite3', sqlite3);
1718

1819
/**
1920
* Register the PowerSync core SQLite extension
2021
*/
2122
module.ccall('powersync_init_static', 'int', []);
2223

24+
console.log('powerync init');
25+
2326
const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
27+
console.log('DbFileName', dbFileName);
2428
// @ts-expect-error The types for this static method are missing upstream
25-
const vfs = await IDBBatchAtomicVFS.create(dbFileName, module, { lockPolicy: 'exclusive' });
26-
sqlite3.vfs_register(vfs, true);
29+
const vfs = await IDBBatchAtomicVFS.create(dbFileName, module, {
30+
lockPolicy: 'exclusive'
31+
});
32+
33+
console.log('vfs before', vfs);
34+
vfs.name = `multipleciphers-${dbFileName}`;
35+
sqlite3.vfs_register(vfs, false);
36+
37+
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [dbFileName, 1]);
38+
console.log('result from creation', createResult);
39+
if (createResult !== 0) {
40+
throw new Error('Failed to create multiple cipher vfs');
41+
}
42+
console.log('vfs after', vfs);
2743

2844
const db = await sqlite3.open_v2(dbFileName);
45+
console.log('db', db);
46+
47+
// const pragma = await sqlite3.exec(db, 'PRAGMA key = "key"');
48+
// console.log('pragma', pragma);
49+
// if (pragma !== SQLite.SQLITE_OK) {
50+
// throw new Error('Failed to set key');
51+
// }
52+
2953
const statementMutex = new Mutex();
3054

3155
/**

0 commit comments

Comments
 (0)