MOBILE-4304 core: Implement insert row id
parent
a7bd1e5f89
commit
ed75657719
|
@ -1,5 +1,5 @@
|
|||
diff --git a/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs b/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs
|
||||
index b86a0aa..a9bf793 100644
|
||||
index b86a0aa..1be2b82 100644
|
||||
--- a/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs
|
||||
+++ b/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs
|
||||
@@ -533,7 +533,7 @@ var sqlite3InitModule = (() => {
|
||||
|
@ -11,7 +11,33 @@ index b86a0aa..a9bf793 100644
|
|||
}
|
||||
|
||||
function getBinary(file) {
|
||||
@@ -12522,7 +12522,7 @@ var sqlite3InitModule = (() => {
|
||||
@@ -10913,6 +10913,10 @@ var sqlite3InitModule = (() => {
|
||||
}
|
||||
},
|
||||
|
||||
+ lastInsertRowId: function () {
|
||||
+ return capi.sqlite3_last_insert_rowid(affirmDbOpen(this).pointer);
|
||||
+ },
|
||||
+
|
||||
dbFilename: function (dbName = 'main') {
|
||||
return capi.sqlite3_db_filename(affirmDbOpen(this).pointer, dbName);
|
||||
},
|
||||
@@ -11877,12 +11881,14 @@ var sqlite3InitModule = (() => {
|
||||
if (!hadColNames) rc.columnNames = [];
|
||||
|
||||
rc.callback = function (row, stmt) {
|
||||
+ const rowId = rc.sql.includes('INSERT') ? db.lastInsertRowId() : undefined;
|
||||
wState.post(
|
||||
{
|
||||
type: theCallback,
|
||||
columnNames: rc.columnNames,
|
||||
rowNumber: ++rowNumber,
|
||||
row: row,
|
||||
+ rowId,
|
||||
},
|
||||
wState.xfer,
|
||||
);
|
||||
@@ -12522,7 +12528,7 @@ var sqlite3InitModule = (() => {
|
||||
return promiseResolve_(sqlite3);
|
||||
};
|
||||
const W = new Worker(
|
||||
|
@ -20,7 +46,7 @@ index b86a0aa..a9bf793 100644
|
|||
);
|
||||
setTimeout(() => {
|
||||
if (undefined === promiseWasRejected) {
|
||||
@@ -13445,7 +13445,7 @@ var sqlite3InitModule = (() => {
|
||||
@@ -13445,7 +13451,7 @@ var sqlite3InitModule = (() => {
|
||||
});
|
||||
return thePromise;
|
||||
};
|
||||
|
|
|
@ -82,16 +82,19 @@ export class WasmSQLiteObject implements SQLiteObject {
|
|||
* @inheritdoc
|
||||
*/
|
||||
async executeSql(statement: string, params?: any[] | undefined): Promise<any> {
|
||||
let insertId: number | undefined = undefined;
|
||||
const rows = [] as unknown[];
|
||||
|
||||
await this.promiser('exec', {
|
||||
sql: statement,
|
||||
bind: params,
|
||||
callback({ row, columnNames }) {
|
||||
callback({ row, columnNames, rowId }) {
|
||||
if (!row) {
|
||||
return;
|
||||
}
|
||||
|
||||
insertId ||= rowId;
|
||||
|
||||
rows.push(columnNames.reduce((record, column, index) => {
|
||||
record[column] = row[index];
|
||||
|
||||
|
@ -106,6 +109,7 @@ export class WasmSQLiteObject implements SQLiteObject {
|
|||
length: rows.length,
|
||||
},
|
||||
rowsAffected: rows.length,
|
||||
insertId,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
export {};
|
||||
|
||||
declare module '@sqlite.org/sqlite-wasm' {
|
||||
|
||||
export interface SqliteRowData {
|
||||
rowId?: number;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue