@@ -848,6 +848,30 @@ export function Factory(Module) {
848
848
return check ( 'sqlite3_vfs_register' , result ) ;
849
849
} ;
850
850
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
+
851
875
function check ( fname , result , db = null , allowed = [ SQLite . SQLITE_OK ] ) {
852
876
if ( allowed . includes ( result ) ) return result ;
853
877
const message = db ? Module . ccall ( 'sqlite3_errmsg' , 'string' , [ 'number' ] , [ db ] ) : fname ;
0 commit comments