Skip to content

Commit

Permalink
v 1.0.4 added sqlite3_update_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
linhttbk97 committed Dec 12, 2023
1 parent 340c668 commit 26254ba
Show file tree
Hide file tree
Showing 29 changed files with 13,186 additions and 13,036 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const db = new SQL.Database();
// NOTE: You can also use new SQL.Database(data) where
// data is an Uint8Array representing an SQLite database file

// create a database from file
const filePath = `sql/data.sqlite`
const db = new SQL.Database(filePath, (tableName)=>{
//todo called when table changed
}, {filename: true})


// Execute a single SQL string that contains multiple statements
let sqlstr = "CREATE TABLE hello (a int, b char); \
Expand Down
12,416 changes: 6,223 additions & 6,193 deletions dist/sql-asm-debug.js

Large diffs are not rendered by default.

270 changes: 135 additions & 135 deletions dist/sql-asm-memory-growth.js

Large diffs are not rendered by default.

266 changes: 133 additions & 133 deletions dist/sql-asm.js

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions dist/sql-wasm-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
"",
["number", "number", "number", "number"]
);
var sqlite3_update_hook = cwrap(
"sqlite3_update_hook",
"number",
["number", "number", "number"]
);
var sqlite3_result_int = cwrap(
"sqlite3_result_int",
"",
Expand All @@ -315,6 +320,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
"",
["number", "string", "number"]
);

var registerExtensionFunctions = cwrap(
"RegisterExtensionFunctions",
"number",
Expand Down Expand Up @@ -903,10 +909,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
* one stored in the byte array passed in first argument
* @param {number[]|string} data An array of bytes representing
* an SQLite database file or a path
* @param {function} onUpdateData the update function to be executed.
* @param {Object} opts Options to specify a filename
*/
function Database(data, { filename = false } = {}) {
console.log("Database constructor called");
function Database(data,onUpdateData, { filename = false } = {}) {
if(filename === false) {
this.filename = "dbfile_" + (0xffffffff * Math.random() >>> 0);
this.memoryFile = true;
Expand All @@ -928,6 +934,15 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
// A list of all user function of the database
// (created by create_function call)
this.functions = {};
if(onUpdateData){
var updateHookFunction = function updateHookCallback(dbName, operation,db, tableName,rowID) {
const tableNameString = UTF8ToString(tableName);
onUpdateData(tableNameString)
}
var func_ptr = addFunction(updateHookFunction, "viiiij");
sqlite3_update_hook(this.db, func_ptr, this);
}

}

/** Execute an SQL query, ignoring the rows it returns.
Expand Down Expand Up @@ -1148,6 +1163,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
return stmt;
};


/** Iterate over multiple SQL statements in a SQL string.
* This function returns an iterator over {@link Statement} objects.
* You can use a for..of loop to execute the returned statements one by one.
Expand Down Expand Up @@ -6556,6 +6572,9 @@ var _sqlite3_close_v2 = Module["_sqlite3_close_v2"] = createExportWrapper("sqlit
/** @type {function(...*):?} */
var _sqlite3_create_function_v2 = Module["_sqlite3_create_function_v2"] = createExportWrapper("sqlite3_create_function_v2");

/** @type {function(...*):?} */
var _sqlite3_update_hook = Module["_sqlite3_update_hook"] = createExportWrapper("sqlite3_update_hook");

/** @type {function(...*):?} */
var _sqlite3_open = Module["_sqlite3_open"] = createExportWrapper("sqlite3_open");

Expand Down
Binary file modified dist/sql-wasm-debug.wasm
Binary file not shown.
226 changes: 113 additions & 113 deletions dist/sql-wasm.js

Large diffs are not rendered by default.

Binary file modified dist/sql-wasm.wasm
Binary file not shown.
Loading

0 comments on commit 26254ba

Please sign in to comment.