Skip to content

Commit 187d9cd

Browse files
added changeset
1 parent 8573556 commit 187d9cd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

.changeset/perfect-radios-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/wa-sqlite': minor
3+
---
4+
5+
Updated from upstream

src/sqlite-api.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,30 @@ export function Factory(Module) {
848848
return check('sqlite3_vfs_register', result);
849849
};
850850

851+
sqlite3.register_table_onchange_hook = function(db, callback) {
852+
// Register hooks for this DB as a global hook
853+
// It will call the global handler above
854+
Module.ccall('register_table_update_hook', 'int', ['number'], [db]);
855+
856+
onTableChangeCallbacks[db] = function(opType, tableNamePtr, rowId) {
857+
// Need to get the string from the pointer
858+
// const tableName = Module.UTF8ToString(Module.getValue(tableNamePtr, '*'));
859+
const memory = new DataView(Module.HEAPU8.buffer);
860+
861+
// Find the null terminator to determine the string length
862+
let length = 0;
863+
while (memory.getUint8(tableNamePtr + length) !== 0) {
864+
length++;
865+
}
866+
867+
// Extract the string content
868+
const stringBytes = new Uint8Array(Module.HEAPU8.buffer, tableNamePtr, length);
869+
const tableName = new TextDecoder().decode(stringBytes);
870+
871+
return callback(opType, tableName, rowId);
872+
};
873+
};
874+
851875
function check(fname, result, db = null, allowed = [SQLite.SQLITE_OK]) {
852876
if (allowed.includes(result)) return result;
853877
const message = db ? Module.ccall('sqlite3_errmsg', 'string', ['number'], [db]) : fname;

0 commit comments

Comments
 (0)